<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"></div><div dir="ltr">Hi Frederic,</div><div dir="ltr"><br></div><div dir="ltr">Lenses (<a href="http://hackage.haskell.org/package/lens">http://hackage.haskell.org/package/lens</a>) are a powerful and well-supported way of peering into data structures. They are a bit of work to learn, but well worth it. </div><div dir="ltr"><br></div><div dir="ltr">Will</div><div dir="ltr"><br>On Sep 6, 2019, at 4:58 PM, PICCA Frederic-Emmanuel <<a href="mailto:frederic-emmanuel.picca@synchrotron-soleil.fr">frederic-emmanuel.picca@synchrotron-soleil.fr</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr"><blockquote type="cite"><span>You don't need a monad instance for this. First of all, you don't even need do syntax to make something "pretty" similar to this.</span><br></blockquote><span></span><br><blockquote type="cite"><span> hdf5 $</span><br></blockquote><blockquote type="cite"><span> group "name" $</span><br></blockquote><blockquote type="cite"><span> [ dataset "name1" array1</span><br></blockquote><blockquote type="cite"><span> , dataset "name2" array2</span><br></blockquote><blockquote type="cite"><span> , group "other-name" $ [</span><br></blockquote><blockquote type="cite"><span> …</span><br></blockquote><span></span><br><span>This is for now the solution I decide to keep., nevertheless thanks for the monad ;).</span><br><span></span><br><span>Now I would like you opinion about a type which allows me to select a node in this tree.</span><br><span></span><br><span>I need to extract a bunch of values from these hdf5 files.</span><br><span>So I discribe a location in the tree, like this with another type quite similar to the first but with only</span><br><span>one child per group. This way there is only one dataset extracted.</span><br><span></span><br><span>(maybe later, I will discuss about extracting multiple dataset ;).</span><br><span></span><br><span>data Hdf5Path sh e</span><br><span> = H5RootPath (Hdf5Path sh e)</span><br><span> | H5GroupPath ByteString (Hdf5Path sh e)</span><br><span> | H5DatasetPath ByteString</span><br><span></span><br><span>hdf5p $ group "name" $ group "otherName" $ dataset "myDataset"</span><br><span></span><br><span>Then I need to write something like this.</span><br><span></span><br><span>withDataset :: File -> Hdf5Path sh e -> (Dataset -> IO r) -> IO r</span><br><span></span><br><span>BUT, I would like to express this path like this</span><br><span></span><br><span>hdf5p :: group <the first encounted> :: group "otherName" $ dataset "mydataset"</span><br><span></span><br><span>So should I define a type and modify the group constructor like this</span><br><span></span><br><span>H5GroupPath BytString (Hdf5Path sh e)</span><br><span></span><br><span>GroupDesc = ByName ByteString</span><br><span> | ByPosition Int</span><br><span> | etc...</span><br><span></span><br><span>H5GroupPath GropDesc (Hdf5Path sh e)</span><br><span></span><br><span>the only problem I see with this is that I need to encode all the strategies in this type.</span><br><span></span><br><span>Is there a better way to do this sort of things.</span><br><span></span><br><span>thanks</span><br><span></span><br><span>Frederic</span><br><span>_______________________________________________</span><br><span>Haskell-Cafe mailing list</span><br><span>To (un)subscribe, modify options or view archives go to:</span><br><span><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a></span><br><span>Only members subscribed via the mailman list are allowed to post.</span></div></blockquote></body></html>