[Haskell-cafe] help designing a function
PICCA Frederic-Emmanuel
frederic-emmanuel.picca at synchrotron-soleil.fr
Wed Feb 12 17:20:33 UTC 2020
Hello,
I try to write a software, which takes a stack of images and produce a data cube.
Depending on the user input obtain via an .ini file, these cube are computed from different kind of projection.
For now I have only two projection QxQyQzProjection and HklProjection.
I prepare the InputXXX for the processXXX functions from the BinocularConfiguration and a function (InputType -> a)
mkInputQxQyQz :: FramesQxQyQzP a => BinocularsConfig -> (InputType -> a) -> IO (InputQxQyQz a)
processQxQyQz :: FramesQxQyQzP a => InputQxQyQz a -> IO ()
mkInputHkl :: FramesHklP a => BinocularsConfig -> (InputType -> a) -> IO (InputHkl a b)
processHkl :: FramesHklP a => InputHkl a b -> IO ()
now I want to write this kind of function, which use the right Projection depending on the type find in the BinocularsConfig
processProjection :: Show a => BinocularsConfig -> (InputType -> a) -> IO ()
processProjection c' f = do
print c'
case (ptype . bProjection $ c') of
QxQyQzProjection -> do
i <- mkInputQxQyQz c' f
print i
processQxQyQz i
HklProjection -> do
i <- mkInputHkl c' f
print i
processHkl i
return ()
Indeed when I compile this code, I have an Error explaining that a FramesHklP a constrain is missing from the processProjection function.
and idem for the FramesQxQyQzP. so I can add both constrains, but in that case I need to implement the two interfaces for each type a.
Indeed this is wrong the `a` is for a specific projection thus I can not create an instance for each kind of Projection.
I do not know If I am clear, but I do not know how to organise my code in order to be able to write this processProjection method.
any help would be appreciate.
thanks
Frederic
More information about the Haskell-Cafe
mailing list