What is wrong with my types signatures.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What is wrong with my types signatures.

PICCA Frederic-Emmanuel
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
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is wrong with my types signatures.

David McBride
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
<[hidden email]> 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
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What is wrong with my types signatures.

PICCA Frederic-Emmanuel
Thanks a lot.

> 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.

This was the problem.

Thanks.

PS: The error message was right (as usual :), but I do not know why I was not able to found the cuprite.
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Loading...