[Haskell-beginners] pipe and IO

David McBride toad3k at gmail.com
Tue Mar 22 17:08:53 UTC 2016


Yield in your producer is of type DataFrameHkI3D -> Producer DataFrameHkl3D
IO ()

But you are putting an (IO DataFrameHkI3D) in as an argument.

You should be able to do something like this:

getDataFrameHkl3D :: DataFrameHkl3DH5SixsUhv -> Producer DataFrameHkl3D IO
()
getDataFrameHkl3D d = do
  n <- lift $ hkl_h5_len (h5mu d)
  frames <- forM [0..n] $ \i -> lift (getDataFrameHkl3D' d i)  -- ::
Producer DataFrameHkl3D IO [DataFrameHkl3D]
  forM_ frames yield

I have a feeling it may be more efficient to yield immediately on each loop
as such:

getDataFrameHkl3D :: DataFrameHkl3DH5SixsUhv -> Producer DataFrameHkl3D IO
()
getDataFrameHkl3D d = do
  n <- lift $ hkl_h5_len (h5mu d)
  forM_ [0..n] (\i -> lift (getDataFrameHkl3D' d i) >>= yield)

You may also substitutde liftIO for lift, if you wish.

On Tue, Mar 22, 2016 at 12:37 PM, PICCA Frederic-Emmanuel <
frederic-emmanuel.picca at synchrotron-soleil.fr> wrote:

> Hello,
>
> Still playing with the Pipe module
>
> here the code I try to write
>
> getDataFrameHkl3D' ::  DataFrameHkl3DH5SixsUhv -> Int -> IO DataFrameHkl3D
> getDataFrameHkl3D' d i = do
>   positions <- get_position (h5mu d) i
>   return $ DataFrameHkl3D { df_n = i
>                           , df_image = positions
>                           }
>
> getDataFrameHkl3D :: DataFrameHkl3DH5SixsUhv -> Producer DataFrameHkl3D IO
> ()
> getDataFrameHkl3D d = do
>   n <- lift $ hkl_h5_len (h5mu d)
>   forM_ [0..n] $ \i -> yield $ getDataFrameHkl3D' d i
>
>
> but when I compile it I get this error message
>
> src/hkl3d.hs:274:3:
>     Couldn't match type `IO DataFrameHkl3D' with `DataFrameHkl3D'
>     Expected type: Proxy X () () DataFrameHkl3D IO ()
>       Actual type: Proxy X () () (IO DataFrameHkl3D) IO ()
>     In a stmt of a 'do' block:
>       forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i
>     In the expression:
>       do { n <- lift $ hkl_h5_len (h5mu d);
>            forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i }
>     In an equation for `getDataFrameHkl3D':
>         getDataFrameHkl3D d
>           = do { n <- lift $ hkl_h5_len (h5mu d);
>                  forM_ [0 .. n] $ \ i -> yield $ getDataFrameHkl3D' d i }
>
> I do not know how to fix my code...
>
> Frederic
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160322/3ce4c1d8/attachment.html>


More information about the Beginners mailing list