[Haskell-beginners] GADTs and method signature

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Fri Aug 26 14:31:52 UTC 2016


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


More information about the Beginners mailing list