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 interpret the definition of MonadState ([email protected])
2. Re: xml light problem or pebkac (Manfred Lotz)
3. Re: Monad operators: multiple parameters (Christopher Howard)
4. Re: Monad operators: multiple parameters (aditya siram)
5. Re: Monad operators: multiple parameters (aditya siram)
6. Re: How to interpret the definition of MonadState
(Henk-Jan van Tuyl)
7. Re: How to interpret the definition of MonadState
(Ertugrul Soeylemez)
8. Re: Monad operators: multiple parameters (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Tue, 07 Jun 2011 11:35:45 -0400
From: [email protected]
Subject: Re: [Haskell-beginners] How to interpret the definition of
MonadState
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; DelSp="Yes";
format="flowed"
Thanks, Daniel.
Quoting Daniel Fischer <[email protected]>:
> On Tuesday 07 June 2011, 16:59:44, [email protected] wrote:
>> I am confused about the definition of MonadState. The opening line
>> looks like this:
>>
>> class Monad m => MonadState s m | m -> s where
>>
>> It is the vertical bar | that confuses me. What does that mean? How
>> would one read this line in "natural language", say English?
>
> The vertical bar signifies a functional dependency (cf. the ghc users'
> guide for details). It says here, that the monad determines the type of the
> state.
Does that mean it's ghc specific, i.e. not in Haskell 98 / 2010?
>
> Read it
>
> class (demanding a Monad instance for m) MonadState m s, m determining s
> uniquely, where ...
>
------------------------------
Message: 2
Date: Tue, 7 Jun 2011 18:14:46 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] xml light problem or pebkac
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Tue, 7 Jun 2011 16:09:41 +0200
Daniel Fischer <[email protected]> wrote:
> >
> >
> > I'm not sure if it is obvious where my mistake here lies. If not I
> > have to try to make this a working minimal example.
>
> I wrote:
> > If you force the result before closing the handle, enough of the
> > file is read to find the desired elements,
>
> You're not forcing the result. You can choose to force in
> getXmlContent by seq'ing on name, location and whatever else fields
> you have, then using a strict return (return $! m') in the
> withBinaryFile action is sufficient, or you can do all the forcing in
> the withBinaryFile action, for example
>
Somehow I had not really understood your first answer.
Indeed
return $! m'
does it nicely.
--
Thanks,
Manfred
------------------------------
Message: 3
Date: Tue, 07 Jun 2011 08:42:51 -0800
From: Christopher Howard <[email protected]>
Subject: Re: [Haskell-beginners] Monad operators: multiple parameters
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 06/07/2011 04:54 AM, Mats Rauhala wrote:
> On 04:30 Tue 07 Jun , Christopher Howard wrote:
>> In a reply to an earlier question, someone told me that "do" expressions
>> are simply syntactic sugar that expand to expressions with the >> and
>>>> = operators. I was trying to understand this (and the Monad class) better.
>>
>> I see in my own experiments that this...
>>
>> main = do ln1 <- getLine
>> putStrLn ln1
>>
>> translates to this:
>>
>> main = getLine >>= \ln1 -> putStrLn ln1
>>
>> However, what does this translate to?:
>>
>> main = do ln1 <- getLine
>> ln2 <- getLine
>> putStrLn (ln1 ++ ln2)
>
> It translates to:
>
> main = getLine >>= \ln1 -> getLine >>= \ln2 -> putStrLn (ln1 ++ ln2)
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
Thank you Fischer and Rauhala for your prompt and helpful responses.
One final point of clarification, on a related note: am I correct in
reasoning that...
main = do let x = expression
/remainder/
is the equivalent of...
main = let x = expression in /expanded remainder/
so that, for example...
main = ln1 <- getline
let ln2 = "suffix"
putStrLn (ln1 ++ ln2)
would translate to...
main = let ln2 = "suffix" in
getLine >>= \ln1 -> putStrLn (ln1 ++ ln2)
This above example works, but I want to be sure I haven't misunderstood
any important technical points.
--
frigidcode.com
theologia.indicium.us
------------------------------
Message: 4
Date: Tue, 7 Jun 2011 11:58:28 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Monad operators: multiple parameters
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
In your example, yes the two would produce the same result, but the
difference with using "let" inside of a do-block is that you have
access to variables captured inside the block. So for example if you
wanted to get input from the user, capitalize it and append a suffix ,
the following functions are equivalent :
import Data.Char(toUpper)
main = let suffix = "suffix" in
do
x <- getLine
let upperCase = map toUpper x
return (upperCase ++ suffix)
main2 = let suffix = "suffix" in
do
x <- getLine
return (map toUpper x ++ suffix)
Notice that in the "let upperCase ..." line in "main" uses "x" which
was defined within the do-block, you would not have access to "x"
outside the do-block. For reading simplicity when the whole function
is one do-block I usually stick the "let"s inside the block.
-deech
On Tue, Jun 7, 2011 at 11:42 AM, Christopher Howard
<[email protected]> wrote:
> On 06/07/2011 04:54 AM, Mats Rauhala wrote:
>> On 04:30 Tue 07 Jun ? ? , Christopher Howard wrote:
>>> In a reply to an earlier question, someone told me that "do" expressions
>>> are simply syntactic sugar that expand to expressions with the >> and
>>>>> = operators. I was trying to understand this (and the Monad class) better.
>>>
>>> I see in my own experiments that this...
>>>
>>> main = do ln1 <- getLine
>>> ? ? ? ? ? putStrLn ln1
>>>
>>> translates to this:
>>>
>>> main = getLine >>= \ln1 -> putStrLn ln1
>>>
>>> However, what does this translate to?:
>>>
>>> main = do ln1 <- getLine
>>> ? ? ? ? ? ln2 <- getLine
>>> ? ? ? ? ? putStrLn (ln1 ++ ln2)
>>
>> It translates to:
>>
>> main = getLine >>= \ln1 -> getLine >>= \ln2 -> putStrLn (ln1 ++ ln2)
>>
>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>
> Thank you Fischer and Rauhala for your prompt and helpful responses.
>
> One final point of clarification, on a related note: am I correct in
> reasoning that...
>
> main = do let x = expression
> ? ? ? ? ?/remainder/
>
> is the equivalent of...
>
> main = let x = expression in /expanded remainder/
>
> so that, for example...
>
> main = ln1 <- getline
> ? ? ? let ln2 = "suffix"
> ? ? ? putStrLn (ln1 ++ ln2)
>
> would translate to...
>
> main = let ln2 = "suffix" in
> ? ? ? ?getLine >>= \ln1 -> putStrLn (ln1 ++ ln2)
>
> This above example works, but I want to be sure I haven't misunderstood
> any important technical points.
>
> --
> frigidcode.com
> theologia.indicium.us
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 5
Date: Tue, 7 Jun 2011 12:01:29 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Monad operators: multiple parameters
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Also I don't really know how "let"s inside a do block desugars but I'm
guessing it's simple substitution so for example the "main" function
below probably translates to:
main3 = let suffix = "suffix" in
getLine >>= \x -> return (map toUpper x ++ suffix)
-deech
On Tue, Jun 7, 2011 at 11:58 AM, aditya siram <[email protected]> wrote:
> In your example, yes the two would produce the same result, but the
> difference with using "let" inside of a do-block is that you have
> access to variables captured inside the block. So for example if you
> wanted to get input from the user, capitalize it and append a suffix ,
> the following functions are equivalent :
> ? ?import Data.Char(toUpper)
> ? ?main = let suffix = "suffix" in
> ? ? ? ? ? ? ? do
> ? ? ? ? ? ? ? ? ? x <- getLine
> ? ? ? ? ? ? ? ? ? let upperCase = map toUpper x
> ? ? ? ? ? ? ? ? ? return (upperCase ++ suffix)
> ? ?main2 = let suffix = "suffix" in
> ? ? ? ? ? ? ? ?do
> ? ? ? ? ? ? ? ? ? ?x <- getLine
> ? ? ? ? ? ? ? ? ? ?return (map toUpper x ++ suffix)
>
> Notice that in the "let upperCase ..." line in "main" uses "x" which
> was defined within the do-block, you would not have access to "x"
> outside the do-block. For reading simplicity when the whole function
> is one do-block I usually stick the "let"s inside the block.
>
> -deech
>
>
> On Tue, Jun 7, 2011 at 11:42 AM, Christopher Howard
> <[email protected]> wrote:
>> On 06/07/2011 04:54 AM, Mats Rauhala wrote:
>>> On 04:30 Tue 07 Jun ? ? , Christopher Howard wrote:
>>>> In a reply to an earlier question, someone told me that "do" expressions
>>>> are simply syntactic sugar that expand to expressions with the >> and
>>>>>> = operators. I was trying to understand this (and the Monad class)
>>>>>> better.
>>>>
>>>> I see in my own experiments that this...
>>>>
>>>> main = do ln1 <- getLine
>>>> ? ? ? ? ? putStrLn ln1
>>>>
>>>> translates to this:
>>>>
>>>> main = getLine >>= \ln1 -> putStrLn ln1
>>>>
>>>> However, what does this translate to?:
>>>>
>>>> main = do ln1 <- getLine
>>>> ? ? ? ? ? ln2 <- getLine
>>>> ? ? ? ? ? putStrLn (ln1 ++ ln2)
>>>
>>> It translates to:
>>>
>>> main = getLine >>= \ln1 -> getLine >>= \ln2 -> putStrLn (ln1 ++ ln2)
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>
>> Thank you Fischer and Rauhala for your prompt and helpful responses.
>>
>> One final point of clarification, on a related note: am I correct in
>> reasoning that...
>>
>> main = do let x = expression
>> ? ? ? ? ?/remainder/
>>
>> is the equivalent of...
>>
>> main = let x = expression in /expanded remainder/
>>
>> so that, for example...
>>
>> main = ln1 <- getline
>> ? ? ? let ln2 = "suffix"
>> ? ? ? putStrLn (ln1 ++ ln2)
>>
>> would translate to...
>>
>> main = let ln2 = "suffix" in
>> ? ? ? ?getLine >>= \ln1 -> putStrLn (ln1 ++ ln2)
>>
>> This above example works, but I want to be sure I haven't misunderstood
>> any important technical points.
>>
>> --
>> frigidcode.com
>> theologia.indicium.us
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
------------------------------
Message: 6
Date: Tue, 07 Jun 2011 21:52:14 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] How to interpret the definition of
MonadState
To: [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Tue, 07 Jun 2011 17:35:45 +0200, <[email protected]> wrote:
> Thanks, Daniel.
>
> Quoting Daniel Fischer <[email protected]>:
>
>> On Tuesday 07 June 2011, 16:59:44, [email protected] wrote:
>>> I am confused about the definition of MonadState. The opening line
>>> looks like this:
>>>
>>> class Monad m => MonadState s m | m -> s where
>>>
>>> It is the vertical bar | that confuses me. What does that mean? How
>>> would one read this line in "natural language", say English?
>>
>> The vertical bar signifies a functional dependency (cf. the ghc users'
>> guide for details). It says here, that the monad determines the type of
>> the
>> state.
>
> Does that mean it's ghc specific, i.e. not in Haskell 98 / 2010?
That is correct.
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--
------------------------------
Message: 7
Date: Tue, 7 Jun 2011 21:55:29 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] How to interpret the definition of
MonadState
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
[email protected] wrote:
> >> class Monad m => MonadState s m | m -> s where
> >>
> >> It is the vertical bar | that confuses me. What does that mean? How
> >> would one read this line in "natural language", say English?
> >
> > The vertical bar signifies a functional dependency (cf. the ghc
> > users' guide for details). It says here, that the monad determines
> > the type of the state.
>
> Does that mean it's ghc specific, i.e. not in Haskell 98 / 2010?
It's a type system extension, which is not in any standard. But
associated types (a special kind of type families) serve essentially the
same purpose in a cleaner way.
class MonadState m where
type StateOf m
get :: m (StateOf m)
put :: StateOf m -> m ()
instance MonadState (State s) where
type StateOf (State s) = s
...
This is equivalent to the definition with fundeps. You can find
TF-based monad transformer libraries. Their package names usually end
with "-tf" to indicate this.
Greets,
Ertugrul
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/
------------------------------
Message: 8
Date: Tue, 7 Jun 2011 22:10:27 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Monad operators: multiple parameters
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="us-ascii"
On Tuesday 07 June 2011, 19:01:29, aditya siram wrote:
> Also I don't really know how "let"s inside a do block desugars but I'm
> guessing it's simple substitution
Yes.
do let a = b
foo
bar
desugars to
let a = b in do { foo; bar; }
(and then further to let a = b in foo >> bar).
A bit more interesting are things like
do x <- foo
let a = b
bar
which desugars to
foo >>= \x -> let a = b in bar
and then the compiler may lift the let-binding out of the (>>=) if a)
that's possible because it doesn't use any values bound in the do-block
before and b) it's deemed a beneficial transformation (which I think it is,
so at least with optimisations, I'd expect such lets to be floated out).
> so for example the "main" function
> below probably translates to:
> main3 = let suffix = "suffix" in
> getLine >>= \x -> return (map toUpper x ++ suffix)
>
> -deech
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 36, Issue 20
*****************************************