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 8679835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:05:08+00:00 2026-06-12T21:05:08+00:00

I am new to Haskell and cannot seem to find a reason for not

  • 0

I am new to Haskell and cannot seem to find a reason for not being able to compile this:

test = foldr (\x y -> y : x) [1]

I am not trying to achieve anything functionally for the dummy function “test”.

Just that I keep getting this error code:

Occurs check: cannot construct the infinite type: a0 = [a0]
    In the first argument of `(:)', namely `y'
    In the expression: y : x
    In the first argument of `foldr', namely `(\ x y -> y : x)'

All I want to do is to be able to concatenate elements from a list, to form another list within an anonymous function defined in another function (in this case, defined in “test”.)

Thanks.

  • 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-06-12T21:05:09+00:00Added an answer on June 12, 2026 at 9:05 pm

    The type of foldr is

    foldr :: (a -> b -> b) -> b -> [a] -> b
    

    so if we try to use it

    test = foldr (\x y -> y : x) [1]
    

    we must have the following types:

    b = Num n => [n]
    

    since the argument for an empty input list has that type, and

    (\x y -> y : x) :: (a -> b -> b)
                    :: Num n => (a -> [n] -> [n])
    

    But the lambda is flip (:) and thus has the type

    (\x y -> y : x) :: [t] -> t -> [t]
    

    and trying to unify that with a -> [n] -> [n], we find

    a == [t]
    t == [n]
    [t] == [n]
    

    which implies t == [t].

    If you don’t flip the cons (:), it will type-check, but the function would be easier expressed as

    test xs = xs ++ [1]
    

    or, point-free

    test = (++ [1])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Haskell and trying to fiddle with some test cases I
Hello I am new at Haskell and i'm having problems trying to get this
I'm very new to Haskell and I'm just trying to find the sum of
I'm new to Haskell and I'm trying out a few tutorials. I wrote this
I am new to Haskell and this mixture of Infix and Prefix notation is
I'm new to Haskell so I apologize if this is an easy question, but
I'm new to haskell guys. I'm trying to write a gcd executable file. ghc
I am new to Haskell. I am trying to write a program which given
I am new to Haskell and I am trying to understand why one needs
I'm rather new to Haskell. The problem is to find the sum of all

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.