[Haskell-beginners] GADTs and method signature

David McBride toad3k at gmail.com
Fri Aug 26 19:22:16 UTC 2016


Once you remove those constructors, when you are operating on 'p' (with
poke, I assume) it doesn't know whether you are operating on a ScPipeParams
ImageXY or a ScPipeParams Image3d'.

The best solution is probably to make instances for Storable ImageXY, and
Storable Image3d' and then Storable a => Storable (ScPipeParams a) which
utilizes the the Storable instance of whichever parameter 'a' you've
provided.

If that is not to your liking.  I think you can use RecordWildCards
extension or maybe it was RecordPuns to allow you to write it something
like one of the following.  I'm not quite sure whether these would work or
not, but it might be worth a try.

scPipeOpen2 d p@(ScPipeParamsImage3d' {}) =
scPipeOpen2 d p@(ScPipeParamsImage3d' {...}) =


On Fri, Aug 26, 2016 at 10:31 AM, PICCA Frederic-Emmanuel <
frederic-emmanuel.picca at synchrotron-soleil.fr> wrote:

> Hello
>
> I have these types
>
> data ImageXY
> data Image3d'
>
> data ScPipeParams a where
>   ScPipeParamsImageXY :: ScBitSize -> Channel -> Modulo -> Sc3du -> Roi ->
> Accumulation -> ScPipeParams ImageXY
>   ScPipeParamsImage3d' :: ScBitSize -> Channel -> Modulo -> Sc3du -> Roi
> -> Accumulation -> ScPipeParams Image3d'
>
>
> and now I write a method
>
>
> scPipeOpen2' (ScDevDesc dev) p =  alloca $ \params -> do
>   poke params p
>   res <- c_sc_pipe_open2 dev (scPipeType p) params
>   checkError res PipeId
>
> scPipeOpen2 :: ScDevDesc -> ScPipeParams a -> IO (PipeId)
> scPipeOpen2 d p@(ScPipeParamsImageXY _ _ _ _ _ _) = scPipeOpen2' d p
> scPipeOpen2 d p@(ScPipeParamsImage3d' _ _ _ _ _ _) = scPipeOpen2' d p
>
> it works fine
>
> In order to avoid these _ _ _ _ _ _, I tryed to removed the @(Constructor
> ____) since I just pass the p parameter to the ' method.
> But in that case , I get this error message
>
> C:\Users\TEMPO\Downloads\tdc\tdc\srcLib.hsc:247:19:
>     No instance for (Storable (ScPipeParams a))
>       arising from a use of scPipeOpen2'
>     In the expression: scPipeOpen2' d p
>     In an equation for `scPipeOpen2':
>         scPipeOpen2 d p = scPipeOpen2' d p
>
> Indeed I already defined two instance of Storable
>
> instance Storable (ScPipeParams ImageXY) where
>   ...
>
> and
>
> instance Storable (ScPipeParams Image3d') where
>   ...
>
> Should I use a special extension in order to be able to write only
>
> scPipeOpen2 d p =  scPipeOpen2' d p
>
>
> thanks for your help
>
> 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/20160826/44dd8cf8/attachment.html>


More information about the Beginners mailing list