[Haskell-beginners] ODP: howto Pipe
Marcin Mrotek
marcin.jan.mrotek at gmail.com
Thu Feb 18 15:46:04 UTC 2016
Hello,
I presume these `c_hkl_<something>` return `IO`? Then you need to `lift` them into `Pipe` (well, `Proxy`).
Best regards,
Marcin Mrotek
-----Wiadomość oryginalna-----
Od: "PICCA Frederic-Emmanuel" <frederic-emmanuel.picca at synchrotron-soleil.fr>
Wysłano: 2016-02-18 15:58
Do: "beginners at haskell.org" <beginners at haskell.org>
Temat: [Haskell-beginners] howto Pipe
Hello
I try to mix my C library and the Pipe module
here the code I am using
solveTraj :: Factory -> Geometry -> Detector -> Sample -> Pipe Engine Geometry IO ()
solveTraj f g d s = do
e <- await
let name = engineName e
withSample s $ \sample ->
withDetector d $ \detector ->
withGeometry f g $ \geometry ->
withEngineList f $ \engines ->
withCString name $ \cname -> do
c_hkl_engine_list_init engines geometry detector sample
engine <- c_hkl_engine_list_engine_get_by_name engines cname nullPtr
n <- c_hkl_engine_pseudo_axis_names_get engine >>= darrayStringLen
yield $ solve' engine n e >>= getSolution0
where
getSolution0 :: ForeignPtr HklGeometryList -> IO Geometry
And I am using this like this
runEffect $ for (each engines) >-> solveTraj factory geometry detector sample >-> P.print
where
[Engine]
engines
But When I compile the code I get this error.
src/Hkl/C.hsc:83:3:
Couldn't match type `IO' with `Proxy () Engine () Geometry IO'
Expected type: Proxy () Engine () Geometry IO ()
Actual type: IO ()
In a stmt of a 'do' block:
withSample s
$ \ sample
-> withDetector d
$ \ detector -> withGeometry f g $ \ geometry -> ...
In the expression:
do { e <- await;
let name = engineName e;
withSample s $ \ sample -> withDetector d $ \ detector -> ... }
In an equation for `solveTraj':
solveTraj f g d s
= do { e <- await;
let name = ...;
withSample s $ \ sample -> withDetector d $ ... }
src/Hkl/C.hsc:91:19:
Couldn't match type `Proxy x'0 x0 () (IO Geometry) m0' with `IO'
Expected type: IO ()
Actual type: Proxy x'0 x0 () (IO Geometry) m0 ()
In a stmt of a 'do' block:
yield $ solve' engine n e >>= getSolution0
In the expression:
do { c_hkl_engine_list_init engines geometry detector sample;
engine <- c_hkl_engine_list_engine_get_by_name
engines cname nullPtr;
n <- c_hkl_engine_pseudo_axis_names_get engine >>= darrayStringLen;
yield $ solve' engine n e >>= getSolution0 }
In the second argument of `($)', namely
`\ cname
-> do { c_hkl_engine_list_init engines geometry detector sample;
engine <- c_hkl_engine_list_engine_get_by_name
engines cname nullPtr;
.... }'
I do not understand why the yield does not produce the right type as output.
I think I missed something big :), but...
Thanks for your help
Fred
_______________________________________________
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/20160218/d77130cd/attachment.html>
More information about the Beginners
mailing list