[Haskell-beginners] What is wrong with my types signatures.
PICCA Frederic-Emmanuel
frederic-emmanuel.picca at synchrotron-soleil.fr
Mon Jan 23 08:48:26 UTC 2017
Hello here a snipset code
class Shape sh => FrameND t sh where
shapeND :: t -> MaybeT IO sh
rowND :: t -> sh -> MaybeT IO (XrdMeshFrame sh)
I have an instance of FrameND
then I created a function which use this class
framesND :: (Shape sh, FrameND a sh) => Pipe a (XrdMeshFrame sh) IO ()
framesND = do
d <- await
sh' <- lift $ runMaybeT $ shapeND d
let n = size sh'
forM_ [0..n-1] (\i' -> do
f <- lift $ runMaybeT $ rowND d (fromIndex sh' i')
when (isJust f) (yield (fromJust f)))
But when I compile it; I get this error message
src/Hkl/XRD.hs:613:55:
Could not deduce (sh ~ Maybe a0)
from the context (Shape sh, FrameND a sh)
bound by the type signature for
framesND :: (Shape sh, FrameND a sh) =>
Pipe a (XrdMeshFrame sh) IO ()
at src/Hkl/XRD.hs:606:13-70
`sh' is a rigid type variable bound by
the type signature for
framesND :: (Shape sh, FrameND a sh) =>
Pipe a (XrdMeshFrame sh) IO ()
at src/Hkl/XRD.hs:606:13
Expected type: Maybe (XrdMeshFrame sh)
Actual type: Maybe (XrdMeshFrame (Maybe a0))
In the first argument of `fromJust', namely `f'
In the first argument of `yield', namely `(fromJust f)'
In the second argument of `when', namely `(yield (fromJust f))'
So I do not undestand why the typse system guess Maybe a0 instead of sh in f
If I read this
f <- lift $ runMaybeT $ rowND d (fromIndex sh' i')
runMaybeT return a (Maybe (XrdMeshFrame sh)) and then I lift it into the Pipe.
So
What is wrong ?
thanks
Frederic
More information about the Beginners
mailing list