Help Reading a Hole Error

47 views
Skip to first unread message

Jimmy P

unread,
Sep 1, 2015, 6:46:09 PM9/1/15
to haskell-exercises
Hi everyone,

I am trying to write the implementation of flatMap. So far I have:

flatMap ::
  (a -> List b)
  -> List a
  -> List b
flatMap f xs = foldRight undefined undefined _undefined

This gives the following error for the type hole:
Found hole ‘_undefined’ with type: List a0
    Where: ‘a0’ is an ambiguous type variable
    Relevant bindings include
      xs :: List a (bound at src/Course/List.hs:266:11)
      f :: a -> List b (bound at src/Course/List.hs:266:9)
      flatMap :: (a -> List b) -> List a -> List b
        (bound at src/Course/List.hs:266:1)
    In the third argument of ‘foldRight’, namely ‘_undefined’
    In the expression: foldRight undefined undefined _undefined
    In an equation for ‘flatMap’:
        flatMap f xs = foldRight undefined undefined _undefined
 
I know the right peg for this hole is xs, but I dont understand why the haskell compiler has given it a type denoted List a0 and how that relates to the type I'm going to use of List a?

I think it has something to do with the fact that the whole could take a superset of the type List a or something? by why then didn't it just call it List b instead of specifically List a0.

Cheers,
Jim

Jimmy P

unread,
Sep 2, 2015, 7:24:01 PM9/2/15
to haskell-exercises
For those playing at home, the answer is that a0 is just another type variable, it could have just as easily called it List c

Tony Morris

unread,
Sep 2, 2015, 7:25:24 PM9/2/15
to Jimmy P, haskell-exercises

The a0 could be anything as long as it isn't a or b.

--
You received this message because you are subscribed to the Google Groups "haskell-exercises" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-exerci...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages