[Haskell-beginners] type def messes up
Daniel Fischer
daniel.is.fischer at web.de
Sat Jun 26 15:49:40 EDT 2010
On Saturday 26 June 2010 21:27:20, prad wrote:
> sometimes i have copied a typedef from a tutorial or demo and get
> errors. i take the typedef out and the program runs fine.
Then ask ghci what the type is, e.g.
Prelude> :t reverse
reverse :: [a] -> [a]
>
> i don't think the problem lies with the person creating the typedef
> because they are very experienced.
Maybe, maybe not.
>
> is it possible that the matter has to do with the interpreter eg hugs
> vs ghci and such?
> or possibly an update of the syntax over time?
Unlikely for simple functions. For advanced stuff that requires extensions,
that can happen.
>
> for instance, i'm going through rex page's "two dozen short lessons in
> haskell" from uni of oklahoma. they use hugs and the error message for
>
> reverse 'x'
>
> is completely different from what i get using ghci.
ghc and hugs give very different error messages, but it boils down to the
same:
hugs:
Hugs> reverse 'x'
ERROR - Type error in application
*** Expression : reverse 'x'
*** Term : 'x'
*** Type : Char
*** Does not match : [a]
ghci:
Prelude> reverse 'x'
<interactive>:1:8:
Couldn't match expected type `[a]' against inferred type `Char'
In the first argument of `reverse', namely 'x'
In the expression: reverse 'x'
In the definition of `it': it = reverse 'x'
Both say that you passed an argument of type Char to a function which works
on lists (of any type).
More information about the Beginners
mailing list