Hello Frederic,

you might want to take a look at free monads and the free library.


Cheers,

Tobias

On 9/2/19 9:20 PM, PICCA Frederic-Emmanuel wrote:
Hello, I try to write a monad instance for this type which  represent the content of an hdf5 file.
This file format is similar to a filesystem, where directories are Group and files Dataset.

I end up with this type.

data Hdf5M a
  = H5Root (Hdf5M a)
  | H5Group ByteString [Hdf5M a]  -- A group can contain other groups and/or datasets
  | forall sh b. (NativeType b, Shape sh) => H5Dataset ByteString (Array F sh b)

type Hdf5 = Hdf5M ()

hdf5 :: Hdf5 -> Hdf5
hdf5 = H5Root

group :: ByteString -> [Hdf5] -> Hdf5
group g = H5Group g

dataset :: (NativeType b, Shape sh) => ByteString -> (Array F sh b) -> Hdf5
dataset = H5Dataset

I tryed to inspire myself from the blaze-html Markup type.

And I would like to be able to describe a contain like this

hdf5 $ do
      group "name" $ do
            dataset "name1" array1
            dataset "name2" array2
            group "other-name" $ do
                     etc...

instead of 

H5Root ( H5Group "name" [ dataset ]...)

the final idea, is to be able to serialize object via a

class ToHdf5 where
    toHdf5 :: a -> Hdf5

So my question is someone can help me design this ?

thanks for your help

Frederic
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.