Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  How to construct complex string (martin)
   2. Re:  How to construct complex string (Stephen Tetley)
   3. Re:  How to construct complex string (martin)
   4. Re:  How to construct complex string (Kim-Ee Yeoh)


----------------------------------------------------------------------

Message: 1
Date: Fri, 09 Aug 2013 19:41:57 +0200
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to construct complex string
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Am 08/09/2013 12:18 AM, schrieb Stephen Tetley:
> Hi Martin

> instance Monad Dot where
>   return a = Dot $ \ uq -> ([],uq,a)
>   m >>= k  = Dot $ \ uq -> case unDot m uq of
>                (g1,uq',r) -> case unDot (k r) uq' of
>                        (g2,uq2,r2) -> (g1 ++ g2,uq2,r2)

Thanks Stephen

I have a related question to the one above: The "case .. of" is just
required to bind the variables left of the "->", as there is only one
alternative, right?

I tried to rewrite this using "where" and was bitten badly, because
inside the "where" uq would not be defined. I found a way to write (a
simplified version of) this using "let .. in", but I had to put the
entire "let .. in" after the "->" in the lambda and it ended up equally
ugly.

So my question is: is "case .. of" the the "where" of lambdas? Are there
alternatives? I find this confusing because "case .. of" looks like a
decision between alternatives, rather than a way to bind variables.



------------------------------

Message: 2
Date: Fri, 9 Aug 2013 19:27:44 +0100
From: Stephen Tetley <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to construct complex string
Message-ID:
        <CAB2TPRA4A-_JY6TqLhEywAse1kgcAeKdb1ctR=cwhk1g+rq...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi Martin

I think case ... of here is equivalent to let ... in the only difference is
that it can avoid growing rightwards. The declaration and body of let would
have to be indented to the same level as the `let` keyword. With case ...
of the consequent expression doesn't have to be indented to the level of
`case` provided it is on a new line.

I don't think I've ever noticed this "typographical trick" of a single case
_case_ in other code.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130809/d91f052e/attachment-0001.html>

------------------------------

Message: 3
Date: Fri, 09 Aug 2013 21:29:32 +0200
From: martin <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How to construct complex string
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Am 08/09/2013 08:27 PM, schrieb Stephen Tetley:

> I don't think I've ever noticed this "typographical trick" of a single
> case _case_ in other code.

Are there other ways of doing this? What do you guys do, when you are
tempted to write "where" but you are behind the "->" of a lambda and you
want to refer to the arguments?




------------------------------

Message: 4
Date: Sat, 10 Aug 2013 04:11:17 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to construct complex string
Message-ID:
        <CAPY+ZdQ7rVexupXy6pKSQ0qhw6K=a85hz8mzggyftccajoz...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Sat, Aug 10, 2013 at 12:41 AM, martin <[email protected]> wrote:

> > instance Monad Dot where
> >   return a = Dot $ \ uq -> ([],uq,a)
> >   m >>= k  = Dot $ \ uq -> case unDot m uq of
> >                (g1,uq',r) -> case unDot (k r) uq' of
> >                        (g2,uq2,r2) -> (g1 ++ g2,uq2,r2)
>
> I tried to rewrite this using "where" and was bitten badly, because
> inside the "where" uq would not be defined.
>

You could write:

m >>= k = Dot f  where
   f uq = (g1 ++ g2, uq2, r2)  where
      (g1, uq', r) = unDot m uq
      (g2, uq2, r2) = unDot (k r) uq'

Doubtless, there has to be a way of revealing the inner structure, which
looks like some state monad with icing on top.

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130810/28b646c9/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 62, Issue 8
****************************************

Reply via email to