<div dir="ltr"><div>Being able to omit []'s and commas is a very natural desire, and it's not clear why would anyone need to engage with monads to achieve this. Although today monads is probably the only way (NB: look at the RebindableSyntax extension), there were a number of discussions over GHC Proposals as to how to retrofit it into the language, e.g. [Record with Syntax][Record-with]. This and (closed unmerged) the [Extra Commas][Extra-Commas] proposal prompted Joachim to start a [wiki page][All-things-layout] gathering this kind of ideas — which I highly recommend to check out and, possibly, brainstorm. Hopefully, it will turn into a new, this time successful GHC proposal.<br></div><div><br></div><div>[Extra-Commas]: <a href="https://github.com/ghc-proposals/ghc-proposals/pull/87">https://github.com/ghc-proposals/ghc-proposals/pull/87</a> <br></div><div>[Record-with]: <a href="https://github.com/ghc-proposals/ghc-proposals/pull/231">https://github.com/ghc-proposals/ghc-proposals/pull/231</a></div><div>[All-things-layout]: <a href="https://gitlab.haskell.org/ghc/ghc/wikis/All-things-layout">https://gitlab.haskell.org/ghc/ghc/wikis/All-things-layout</a></div><div><br></div><div>--</div><div>Kind regards, Artem<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 3 Sep 2019 at 13:42, MarLinn <<a href="mailto:monkleyon@gmail.com">monkleyon@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div bgcolor="#FFFFFF">
<div class="gmail-m_-4474396324877339411moz-cite-prefix">Hi.</div>
<div class="gmail-m_-4474396324877339411moz-cite-prefix"><br>
</div>
<blockquote type="cite">
<pre class="gmail-m_-4474396324877339411moz-quote-pre">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)
[…]
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...
</pre>
</blockquote>
<p>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.</p>
<pre class="gmail-m_-4474396324877339411moz-quote-pre"> hdf5 $
group "name" $
[ dataset "name1" array1
, dataset "name2" array2
, group "other-name" $ [
…</pre>
<p>But if you insist, you can just use an existing monad like
WriterT. For example (simplified):</p>
<pre> data Composite a = Base a | Composite [Composite a]
type CompositeWriter a = Writer [Composite a] ()
base = tell . pure . Base
composite = censor (pure . Composite)
asComposite = Composite . snd . runWriter
test = asComposite $ do
base 'a'
base 'b'
composite $ do
base 'c'
base 'd'
</pre>
<p>Hope that helps.<br>
</p>
</div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>