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: general structuring of "foreach" logic in IO
(John M. Dlugosz)
2. Re: general structuring of "foreach" logic in IO
(Brandon Allbery)
3. Re: How do I use Guards in record syntax? (Bob Ippolito)
4. Why getArgs is in the IO monad (Mike Meyer)
5. Re: general structuring of "foreach" logic in IO (David Thomas)
6. Re: Why getArgs is in the IO monad (Michael Orlitzky)
----------------------------------------------------------------------
Message: 1
Date: Mon, 14 Apr 2014 13:37:04 -0500
From: "John M. Dlugosz" <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] general structuring of "foreach"
logic in IO
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 4/14/2014 10:47 AM, Brandon Allbery wrote:
>
>
> But it is the *compiler's* problem. "Constant" means "known at compile time"
> to the compiler.
>
Pure means pure at run-time over the life of the executable. Just because the
compiler
doesn't know what it is (had it cared to evaluate it at compile time) doesn't
mean it's
not pure.
> Although I wonder if you'd be happier with getArgs >>= mapM_ (do ...).
That's what I ended up with when I stopped fiddling with that particular line.
------------------------------
Message: 2
Date: Mon, 14 Apr 2014 14:42:08 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] general structuring of "foreach"
logic in IO
Message-ID:
<cakfcl4vu-akk8bntvs7rox6cen6t-ropo7bbamcksz0fpbb...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Mon, Apr 14, 2014 at 2:37 PM, John M. Dlugosz
<[email protected]>wrote:
> On 4/14/2014 10:47 AM, Brandon Allbery wrote:
>
>> But it is the *compiler's* problem. "Constant" means "known at compile
>> time" to the compiler.
>>
>
> Pure means pure at run-time over the life of the executable. Just because
> the compiler doesn't
To you. To the compiler, and to me actually, if it is not known at compile
time then it cannot be pure; it may not vary over an individual run of the
program but it can vary over the lifetime of the program itself. If I
cannot know it *statically* --- at compile time, since it is the compiler
that needs to know that it is static --- then it is not pure.
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140414/2b0272ef/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 14 Apr 2014 11:44:03 -0700
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How do I use Guards in record syntax?
Message-ID:
<CACwMPm_QGDbW3FXd2i1PZow3FHMtUhJNcaO=jaqbeapk5fy...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
You wouldn't even need to match True and False, you could match the String
you're looking for.
convert ot = Trade { price = oldprice ot,
amount = oldamount ot,
buysell = case oldbuysell ot of
"buy" -> Buy
"sell" -> Sell
_ -> Unknown
}
On Mon, Apr 14, 2014 at 11:36 AM, Dimitri DeFigueiredo <
[email protected]> wrote:
> Thanks everyone :-)
>
> I think the "case of" is what I was looking for. I keep thinking of using
> "case of" as in pattern matching to find the "Shape" of the result of an
> expression and of using guards to evaluate predicates. Forgetting that True
> and False are constructors themselves. I just have to change that mindset.
>
> Cheers,
>
> Dimitri
>
>
> Em 14/04/14 09:04, Gesh escreveu:
>
> On April 14, 2014 9:03:20 AM GMT+03:00, Dimitri DeFigueiredo <
>> [email protected]> wrote:
>>
>>> I'm having some trouble understanding where I can or cannot use guards
>>> inside record syntax. I'm writing a simple conversion routine, but I am
>>>
>>> not able to write it without inserting an extra let. Do I need a let
>>> expression here? Am I missing something?
>>>
>>> --------------
>>> data OldTrade = OldTrade {
>>> oldprice :: Double ,
>>> oldamount :: Double ,
>>> oldbuysell :: String -- "buy", "sell" or ""
>>> } deriving( Eq, Show)
>>>
>>>
>>> data BuyOrSell = Buy | Sell | Unknown deriving(Eq, Show)
>>>
>>> data Trade = Trade {
>>> price :: Double ,
>>> amount :: Double ,
>>> buysell :: BuyOrSell
>>> } deriving( Eq, Show)
>>>
>>> convert :: OldTrade -> Trade
>>>
>>> convert ot = Trade { price = oldprice ot,
>>> amount = oldamount ot,
>>> buysell = let x | oldbuysell ot == "buy" = Buy
>>> | oldbuysell ot == "sell" = Sell
>>> | otherwise = Unknown
>>> in x
>>> }
>>>
>>> -- how do I eliminate the 'let' expression here?
>>> -- I wanted to write something like:
>>> --
>>> -- buysell | oldbuysell ot == "buy" = Buy
>>> -- | oldbuysell ot == "sell" = Sell
>>> -- | otherwise = Unknown
>>>
>>> --------------
>>>
>>> Thanks!
>>>
>>> Dimitri
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>> Note that this has nothing to do with record syntax specifically. Rather,
>> what you're asking is how to write a multi-way if expression. Your way is
>> to introduce a local binding using a let statement, which allows you to use
>> pattern guards as you did.
>> Usually, bowever, you'd use a case statement to avoid the binding.
>> However, you could use the MultiWayIf LANGUAGE pragma, as suggested
>> elsewhere in this thread. Or you could float out the binding to a where
>> clause, except that doesn't seem to be what you're looking for.
>> Hoping to help,
>> Gesh
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
> _______________________________________________
> 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/20140414/e47bb9b4/attachment-0001.html>
------------------------------
Message: 4
Date: Mon, 14 Apr 2014 14:20:27 -0500
From: Mike Meyer <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Why getArgs is in the IO monad
Message-ID:
<CAD272pB2zrSEnhGUhTaoY3xhUMNXWyNb==xpklbw8vz-5db...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
>
>
> From: "John M. Dlugosz" <[email protected]>
> (And that begs the question of why getArgs needs to be monadic in the
> first place. It
> doesn't change its value; it's a strict constant at run-time, and not
> knowing it at
> compile time is my problem how?)
>
Actually, the value of the arguments can be changed - at least on some
platforms. They are writable from C, if nothing else. What should getArgs
do if some ffi changes the arguments before it's called?
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140414/f97e34f3/attachment-0001.html>
------------------------------
Message: 5
Date: Mon, 14 Apr 2014 12:30:40 -0700
From: David Thomas <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] general structuring of "foreach"
logic in IO
Message-ID:
<CAJUDvcgpWPy0PJGi6XXKrRcpHKwNcOMWWv+fyVKRc=gogzq...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
getArgs is not pure in the presence of withArgs.
This is actually what we want; testing/exercising code that uses
getArgs would be a pain otherwise.
On Mon, Apr 14, 2014 at 11:42 AM, Brandon Allbery <[email protected]> wrote:
> On Mon, Apr 14, 2014 at 2:37 PM, John M. Dlugosz <[email protected]>
> wrote:
>>
>> On 4/14/2014 10:47 AM, Brandon Allbery wrote:
>>>
>>> But it is the *compiler's* problem. "Constant" means "known at compile
>>> time" to the compiler.
>>
>>
>> Pure means pure at run-time over the life of the executable. Just because
>> the compiler doesn't
>
>
> To you. To the compiler, and to me actually, if it is not known at compile
> time then it cannot be pure; it may not vary over an individual run of the
> program but it can vary over the lifetime of the program itself. If I cannot
> know it *statically* --- at compile time, since it is the compiler that
> needs to know that it is static --- then it is not pure.
>
> --
> brandon s allbery kf8nh sine nomine associates
> [email protected] [email protected]
> unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 6
Date: Mon, 14 Apr 2014 15:41:03 -0400
From: Michael Orlitzky <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Why getArgs is in the IO monad
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 04/14/2014 03:20 PM, Mike Meyer wrote:
>
> From: "John M. Dlugosz" <[email protected]
> <mailto:[email protected]>>
> (And that begs the question of why getArgs needs to be monadic in
> the first place. It
> doesn't change its value; it's a strict constant at run-time, and
> not knowing it at
> compile time is my problem how?)
>
>
> Actually, the value of the arguments can be changed - at least on some
> platforms. They are writable from C, if nothing else. What should
> getArgs do if some ffi changes the arguments before it's called?
>
You can do it right from within Haskell:
Prelude> import System.Environment
Prelude System.Environment> getArgs
[]
Prelude System.Environment> withArgs ["foo"] $ getArgs
["foo"]
It's useful if you have a command-line interface and the user mistypes
something; all you have to do is continue as if they passed "--help"
instead of a separate code path.
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 70, Issue 31
*****************************************