Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. GADTs and method signature (PICCA Frederic-Emmanuel)
2. Re: GADTs and method signature (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Fri, 26 Aug 2016 14:31:52 +0000
From: PICCA Frederic-Emmanuel
<[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] GADTs and method signature
Message-ID:
<a2a20ec3b8560d408356cac2fc148e53bb2c4...@sun-dag3.synchrotron-soleil.fr>
Content-Type: text/plain; charset="us-ascii"
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
------------------------------
Message: 2
Date: Fri, 26 Aug 2016 15:22:16 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] GADTs and method signature
Message-ID:
<CAN+Tr43wPxuF8breue95M=vr7v+uydh5ed-1o7pkb4donjk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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 <
[email protected]> 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
> [email protected]
> 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-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 98, Issue 20
*****************************************