Hello i have the following problem:
I am constructing a parametric newtype
over a method and i do not know how to explictly tell GHCI
: I want you to instiantiate this newtype using this type parameter
newtype M a = M {fu::a->Int}
var = M (\s-> length (s:"asa")) #tell him i want the type parameter to be Char
b = (fu var) 'c'
What i expect to get is : 4
because length 'c':"aaa"==4
What i do get is :
interactive>:118:5: error:
* Couldn't match expected type `A [Char]'
with actual type `Ghci30.A [Char]'
NB: `Ghci30.A' is defined at <interactive>:100:1-25
`A' is defined at <interactive>:109:1-25
* In the first argument of `fu', namely `b'
In the expression: (fu b) "asa"
In an equation for `it': it = (fu b) "asa"
When you see names like
Ghci30.A [Char]
, this means that you have redefined your typeA
in GHCi. This would not be an issue if you used a proper.hs
file and reloaded it.Consider this GHCi session:
What should be the output? The type of
x
isA
, but it's not the same typeA
having aChar
inside. GHCi will print the type asYou won't get the error again if you (re-)define
x
after you redefine the typeA
.If your case, the
x
to be redefined is likelyfu
, which is still referring to the oldA
. Check it with:t fu
: if it mentionsGhci30.A
, that's it.For non trivial definitions, I'd recommend to use a
.hs
file and reload it, so to avoid any trouble.