[Haskell-beginners] What is wrong with my types signatures.

David McBride toad3k at gmail.com
Mon Jan 23 13:25:14 UTC 2017


Here's my guess.  I can't be sure without class instances and some
function types that are not in code.

sh' <- lift $ runMaybeT $ shapeND d :: Pipe a (XrdMeshFrame sh) IO (Maybe sh?)
...

f <- lift $ runMaybeT $ rowND d (fromIndex sh' i') -- <- sh' is (Maybe
sh), guessing that fromIndex does not take a Maybe.

On Mon, Jan 23, 2017 at 3:48 AM, PICCA Frederic-Emmanuel
<frederic-emmanuel.picca at synchrotron-soleil.fr> wrote:
> 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
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


More information about the Beginners mailing list