Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 842577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:59:10+00:00 2026-05-15T05:59:10+00:00

I am a beginner interested in Haskell, and I have been trying to implement

  • 0

I am a beginner interested in Haskell, and I have been trying to implement the flatmap (>>=) on my own to better understand it. Currently I have

flatmap :: (t -> a) -> [t] -> [a]  
flatmap _ [] = []  
flatmap f (x:xs) = f x : flatmap f xs  

which implements the “map” part but not the “flat”.
Most of the modifications I make result in the disheartening and fairly informationless

Occurs check: cannot construct the infinite type: a = [a]  
    When generalising the type(s) for `flatmap' 

error.

What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:59:10+00:00Added an answer on May 15, 2026 at 5:59 am

    An error like this happens when the type signature you specify does not match the actual type of the function. Since you didn’t show the code that causes the error, I have to guess, but I presume you changed it to something like this:

    flatmap _ [] = []  
    flatmap f (x:xs) = f x ++ flatmap f xs
    

    Which as it happens, is perfectly correct. However if you forgot to also change the type signature the following will happen:

    The type checker sees that you use ++ on the results of f x and flatmap f xs. Since ++ works on two lists of the same type, the type checker now knows that both expressions have to evaluate to lists of the same type. Now the typechecker also knows that flatmap f xs will return a result of type [a], so f x also has to have type [a]. However in the type signature it says that f has type t -> a, so f x has to have type a. This leads the type checker to conclude that [a] = a which is a contradiction and leads to the error message you see.

    If you change the type signature to flatmap :: (t -> [a]) -> [t] -> [a] (or remove it), it will work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a beginner's question, but I am interested in learning what's going on
I'm interested in JMonkey for some fun projects, but when I search Google to
VB beginner here. My For... Next Loop will not work and I cannot for
beginner here... what am i missing? i define a global variable that is a
Beginner question... How different is define($a,365); from $a = 365; ? Thanks! JDelage
Complete beginner here. I want to create a new tab on each page that
The beginner tutorial I've followed said I should create a namespace on the window,
level: beginner Below snippet is part of code that counts letters in an array.
Complete beginner so I'm probably missing something obvious but... I can't seem to combine
I am new to both JAVA and Google App Engine. My Interest in Java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.