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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:14:51+00:00 2026-06-03T21:14:51+00:00

I am not a Haskell pro. Today I had a somewhat bizarre experience with

  • 0

I am not a Haskell pro. Today I had a somewhat bizarre experience with the type system today. The second line of this will cause a type error. The problem is the maxdiag (as:bs:cs:ds) bit of the second line:

maxdiag ((a:as):(b:bs):(c:cs):(d:ds):xs) len =
  maximum [a*(bs !! 0)*(cs !! 1)*(ds !! 2), maxdiag (as:bs:cs:ds) (len-1)]

It fails with the following error:

Occurs check: cannot construct the infinite type: a0 = [a0]
Expected type: [[a0]]
  Actual type: [a0]
In the second argument of `(:)', namely `ds'
In the second argument of `(:)', namely `cs : ds'

When I change the offending part of the second line to maxdiag (as:bs:cs:ds:xs), so that it reads

maxdiag ((a:as):(b:bs):(c:cs):(d:ds):xs) len =
  maximum [a*(bs !! 0)*(cs !! 1)*(ds !! 2), maxdiag (as:bs:cs:ds:xs) (len-1)]

… then there is no error. Similarly, if I replace it with maxdiag (as:bs:cs:(ds:xs)) it succeeds. My questions are

  1. What does this error mean?
  2. Why has it occurred?
  3. Why do these two seemingly different things fix it?
  • 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-03T21:14:52+00:00Added an answer on June 3, 2026 at 9:14 pm

    The thing to remember is that (:) has the type a -> [a] -> [a], so its first argument is an element, while the second argument is a list with that element type. If the elements are themselves lists, this becomes [a] -> [[a]] -> [[a]].

    In your example, as, bs, cs and ds all have type [a], while xs has type [[a]], so cs:ds is an error while ds:xs is well-typed.

    The reason for that particular error message is that when you try to use (:) on two things of the same type b, the only way that would work is if b was the same type as [b], but that would be an infinite type which is not allowed.

    For the other question, the (:) operator is right-associative, so as:bs:cs:ds:xs is the same as as:(bs:(cs:(ds:xs))) and also as:bs:cs:(ds:xs).

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

Sidebar

Related Questions

In Haskell function type ( -> ) is given, it's not an algebraic data
It seems that Haskell does not the type of symbol as that in Racket?
I want to do something like this in Haskell, but the compiler is not
While learning Haskell I had the feeling that the authors where not always telling
I'm trying to implement the Miller test in Haskell (Not Miller-Rabin.) I'm dealing with
Is there some function in haskell that evaluates to (filter p xs, filter (not.p)
I'm writing a parallel Haskell program using Strategies. It's not doing what it's supposed
Not sure if this counts as programming related, it's a tool that I use.
(Not to be confused with Xunit , a popular .Net unit testing library.) Today
Not exactly about programming, but I need help with this. I'm running a development

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.