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: data, records and functions (Emanuel Koczwara)
2. How do I declare a set? (Heinrich Ody)
3. Re: How do I declare a set? (David McBride)
4. Re: Is my understanding of ">>=" correct? (Sylvain HENRY)
----------------------------------------------------------------------
Message: 1
Date: Thu, 21 Feb 2013 12:17:28 +0100
From: Emanuel Koczwara <[email protected]>
Subject: Re: [Haskell-beginners] data, records and functions
To: [email protected], The Haskell-Beginners Mailing List -
Discussion of primarily beginner-level topics related to Haskell
<[email protected]>
Message-ID: <1361445448.20925.8.camel@emanuel-Dell-System-Vostro-3750>
Content-Type: text/plain; charset="UTF-8"
Hi,
Dnia 2013-02-21, czw o godzinie 02:48 +0000, Peter Hall pisze:
> > It's first time I see function type (and where is definition?) in
> record
> > syntax. Can somebody explain this?
>
>
> There's no definition, it's a parameter to the constructor, so the
> function can be anything. Taking a much simpler example, you'll be
> familiar with, if you do:
>
>
> data Foo a = Foo a
>
>
> then the first argument to the Foo constructor also doesn't have a
> definition. But when you use it to construct a value, then you provide
> one:
>
>
> myFoo = Foo 3
>
>
> Likewise, when you construct an Ord value, you supply a function as
> the value for the 'less' parameter:
>
>
> numOrd = Ord { less = (<) }
>
>
> or you could use a different function for a different purpose:
>
>
> listLengthOrd = Ord { less = \ a b => length a < length b }
>
>
>
>
>
>
> Hope that helps,
>
>
> Peter
Thanks, it is clear now. I was missing that fields can be functions (a
field can hold a function).
-- here second field is a function
data Command a = Command a (a -> a)
-- do something "useful" with that
executeCommand :: Command a -> a
executeCommand (Command param function) = function param
-- test
executeCommand (Command 5 succ) == 6
Thank you, it was so simple :)
Emanuel
------------------------------
Message: 2
Date: Fri, 22 Feb 2013 00:43:41 +0100
From: Heinrich Ody <[email protected]>
Subject: [Haskell-beginners] How do I declare a set?
To: [email protected]
Message-ID:
<camc+g-nsuc0pfwj2hyla8oz_elb-rcmswfhqetxf60yo63d...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
with [1,2] I can declare a list. Is there a similar notation for sets?
Currently the only way I know is 'Set.fromList [1,2]' which is unhandy...
Regards,
Heinrich
------------------------------
Message: 3
Date: Thu, 21 Feb 2013 20:29:08 -0500
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] How do I declare a set?
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<can+tr42ojqejx6bgtqiymu2pezjejnledx4udnjwvrqq5qh...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
At the moment, no. There has been a small push toward an OverloadedLists
extension, which would allow you to use list syntax for anything that has a
fromList (there would probably be an IsList class similar to the IsString
class). I'm not sure where that has gone. I know there were several
competing implementations.
On Thu, Feb 21, 2013 at 6:43 PM, Heinrich Ody <[email protected]>wrote:
> Hi,
>
> with [1,2] I can declare a list. Is there a similar notation for sets?
> Currently the only way I know is 'Set.fromList [1,2]' which is unhandy...
>
> Regards,
> Heinrich
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130221/4ccb3389/attachment-0001.htm>
------------------------------
Message: 4
Date: Fri, 22 Feb 2013 11:34:02 +0100
From: Sylvain HENRY <[email protected]>
Subject: Re: [Haskell-beginners] Is my understanding of ">>=" correct?
To: [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi,
I tried to explain Haskell IO in an introductory talk. Slides are
available here:
http://www.sylvain-henry.info/home/data/uploads/teaching/shenry-slides-haskell-intro-2013.pdf
You may find the "Real World Haskell" section interesting to understand
monads. I use explicit World variables to explain how operations are
sequenced. It helped me to think about it this way when I learned it.
Cheers
Sylvain
Le 19/02/2013 20:13, Martin Drautzburg a ?crit :
> Hello all,
>
> It took me quite some time to understand >>=. What confused me, was that the
> second operand is a function, not just a Monad. I believe I am beginning to
> see the light.
>
> First there is no way to sequence operations by just writing one after the
> other. However we can chain operations by passing the output of one operation
> to the next. But this does not not allow capturing the intermediate results.
> With >>= the output of one operation gets magically bound to the parameter of
> the function and remains in scope all the way through.
>
> I was confused by the signature m a -> (a -> mb) -> mb because it looks like
> there is (as second parameter) a function which returns a Monad. But I doubt I
> ever saw such a function, in the sense that it does something intelligent. It
> is typically a function that does not do a whole lot with its parameter, but
> just returns another Monad, such that its parameter is bound to the result of
> the previous expression.
>
> But it could be done:
>
> do
> x <- SomeMonad
> y <- someCleverlyConstructedMonad x
>
> If I want to see the function of the >>= signature I have to read the do block
> right->left (following the arrow) and then diagonally to the lower right. The
> diagonal steps reveal the function. In the above example we have
>
> \x -> someCleverlyConstructedMonad
>
> but many times I just see
>
> do
> x <- SomeMonad
> y <- someOtherMonad
>
> and the function does not do anything intelligent but just binds x and
> enforces the sequence of operations.
>
> is this about right?
>
>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 56, Issue 34
*****************************************