No subject
Sun Oct 23 10:51:38 CEST 2011
instance of 'Thing' to use, so it is unable to look up the correct
implementation of 'doSomething' (or the correct implementation of
'decode').
Antoine
> readThing :: ( Thing a ) =3D> FilePath -> IO a
> readThing f =3D
> =C2=A0 =C2=A0return . decode . decompress =3D<< B.readFile f
>
> writeThing :: ( Thing a ) =3D> FilePath -> a -> IO ()
> writeThing f =3D B.writeFile f . compress . encode
>
> main =3D do
> =C2=A0a <- readThing "file1.txt"
> =C2=A0a' <- doSomething a
> =C2=A0writeThing "file2.txt" a'
> ----------
>
> And here's the compiler error I get.
>
> Amy.hs:18:3:
> =C2=A0 =C2=A0Ambiguous type variable `a0' in the constraint:
> =C2=A0 =C2=A0 =C2=A0(Thing a0) arising from a use of `writeThing'
> =C2=A0 =C2=A0Probable fix: add a type signature that fixes these type var=
iable(s)
> =C2=A0 =C2=A0In the expression: writeThing "file2.txt" a'
> =C2=A0 =C2=A0In the expression:
> =C2=A0 =C2=A0 =C2=A0do { a <- readThing "file1.txt";
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 a' <- doSomething a;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writeThing "file2.txt" a' }
> =C2=A0 =C2=A0In an equation for `main':
> =C2=A0 =C2=A0 =C2=A0 =C2=A0main
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D do { a <- readThing "file1.txt";
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 a' <- doSomething=
a;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writeThing "file2=
.txt" a' }
>
> Is there a way to fix my code? I tried adding a type signature, e.g.,
>
> =C2=A0a <- readThing "file1.txt" :: (Thing t) =3D> IO t
> =C2=A0a' <- doSomething a :: (Thing t) =3D> IO t
>
> but then it says...
>
> =C2=A0 =C2=A0Couldn't match type `t0' with `t'
> =C2=A0 =C2=A0 =C2=A0because type variable `t' would escape its scope
> =C2=A0 =C2=A0This (rigid, skolem) type variable is bound by
> =C2=A0 =C2=A0 =C2=A0an expression type signature: Thing t =3D> IO t
> =C2=A0 =C2=A0The following variables have types that mention t0
> =C2=A0 =C2=A0 =C2=A0a :: t0 (bound at Amy.hs:16:3)
> =C2=A0 =C2=A0In a stmt of a 'do' expression:
> =C2=A0 =C2=A0 =C2=A0 =C2=A0a' <- doSomething a :: Thing t =3D> IO t
> =C2=A0 =C2=A0In the expression:
> =C2=A0 =C2=A0 =C2=A0do { a <- readThing "file1.txt" :: Thing t =3D> IO t;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 a' <- doSomething a :: Thing t =3D> IO=
t;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writeThing "file2.txt" a' }
> =C2=A0 =C2=A0In an equation for `main':
> =C2=A0 =C2=A0 =C2=A0 =C2=A0main
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D do { a <- readThing "file1.txt" :: =
Thing t =3D> IO t;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 a' <- doSomething=
a :: Thing t =3D> IO t;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 writeThing "file2=
.txt" a' }
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
More information about the Beginners
mailing list