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. How to process a list that contains "undefined" values?
(Costello, Roger L.)
2. Re: How to process a list that contains "undefined" values?
(David Place)
3. Re: How to process a list that contains "undefined" values?
(Daniel Fischer)
4. Re: How to process a list that contains "undefined" values?
(Brandon Allbery)
5. Re: How to process a list that contains "undefined" values?
(David Place)
6. Re: How to process a list that contains "undefined" values?
(David Place)
7. Understandig types ([email protected])
8. Re: Understandig types (David Place)
9. code explanation ([email protected])
10. Re: code explanation (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Sat, 2 Jul 2011 10:09:05 -0400
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] How to process a list that contains
"undefined" values?
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi Folks,
How would you find the maximum value in this list:
[undefined, 10, undefined, 20]
Is it bad practice to create lists that contain undefined values?
If yes, what is a better way to express in a list a "no value
present/available" value?
For example would it be better to express the above list using Maybe:
[Nothing, Just 10, Nothing, Just 20]
Or perhaps something else?
What do you recommend?
/Roger
------------------------------
Message: 2
Date: Sat, 2 Jul 2011 10:26:16 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] How to process a list that contains
"undefined" values?
To: "Costello, Roger L." <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jul 2, 2011, at 10:09 AM, Costello, Roger L. wrote:
> For example would it be better to express the above list using Maybe:
>
> [Nothing, Just 10, Nothing, Just 20]
That is exactly the right way to do it.
> Or perhaps something else?
>
> What do you recommend?
------------------------------
Message: 3
Date: Sat, 2 Jul 2011 16:32:37 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] How to process a list that contains
"undefined" values?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Saturday 02 July 2011, 16:09:05, Costello, Roger L. wrote:
> Hi Folks,
>
> How would you find the maximum value in this list:
>
> [undefined, 10, undefined, 20]
Not. There is no proper maximum in the presence of undefined.
If you absolutely have to do something like that, you would have to use
Control.Exception.catch to catch the undefined values and ignore
them/remove them from the list. But if your undefined values are not so
nice as Prelude.undefined but actually nonterminating computations,
calculating the maximum won't terminate either.
>
> Is it bad practice to create lists that contain undefined values?
That depends on how they will be further processed. Sometimes it's
perfectly fine to have undefined values in a list, sometimes not.
>
> If yes, what is a better way to express in a list a "no value
> present/available" value?
>
> For example would it be better to express the above list using Maybe:
>
> [Nothing, Just 10, Nothing, Just 20]
Yes. If possible, indicating the absence of a value via Maybe is the right
thing to do. Or something including a message why there is no value in a
particular place, like Either err val.
>
> Or perhaps something else?
>
> What do you recommend?
[Maybe Integer], [Either Message Integer], whatever is more appropriate;
then you can use functions like catMaybes or partitionEithers, rights,
lefts, ... to cleanly process the list.
------------------------------
Message: 4
Date: Sat, 2 Jul 2011 11:04:37 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] How to process a list that contains
"undefined" values?
To: "Costello, Roger L." <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<CAKFCL4VTTF2=n-b+UO5W5AWPipVJFybLiAOEyBHXjA0Oaz=u...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Sat, Jul 2, 2011 at 10:09, Costello, Roger L. <[email protected]> wrote:
> How would you find the maximum value in this list:
>
> ? ? [undefined, 10, undefined, 20]
>
> Is it bad practice to create lists that contain undefined values?
"undefined" is not "null"; "Nothing" is. "undefined" represents a
computation that never produces a result: an infinite loop or a
crash. Some but by far not all of these can
be characterized at runtime and turned into exceptions. (The literal
Prelude.undefined explicitly throws an exception, but could just as
well be "let x = x in x" and let the ghc runtime catch it.)
The type tells you this right out, by the way:
> undefined :: a
What can you do with a "value" that can be any conceivable type, and
about which nothing else can be said? It has no handles, no behavior;
the only possible interpretation is that it's not a value at all.
--
brandon s allbery ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [email protected]
wandering unix systems administrator (available) ? ? (412) 475-9364 vm/sms
------------------------------
Message: 5
Date: Sat, 2 Jul 2011 11:25:51 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] How to process a list that contains
"undefined" values?
To: Brandon Allbery <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jul 2, 2011, at 11:04 AM, Brandon Allbery wrote:
> The type tells you this right out, by the way:
>
>> undefined :: a
>
> What can you do with a "value" that can be any conceivable type, and
> about which nothing else can be said? It has no handles, no behavior;
> the only possible interpretation is that it's not a value at all.
Its type makes undefined valuable in creating polymorphic functions. You can
see many examples of it in my article for the Monad.Reader:
"How to refold a map."
> http://www.haskell.org/wikiupload/6/6a/TMR-Issue11.pdf
"undefined" is rendered by the symbol for "bottom" in the formatted code.
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
------------------------------
Message: 6
Date: Sat, 2 Jul 2011 11:31:16 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] How to process a list that contains
"undefined" values?
To: Brandon Allbery <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jul 2, 2011, at 11:04 AM, Brandon Allbery wrote:
> What can you do with a "value" that can be any conceivable type, and
> about which nothing else can be said?
Also, here's an implementation of incremental maps using finger trees and
undefined.
> http://hpaste.org/48636
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
------------------------------
Message: 7
Date: Sat, 02 Jul 2011 08:37:29 -0700
From: [email protected]
Subject: [Haskell-beginners] Understandig types
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi everyone. I've got a few questions about the Haskell programming
language.
1) what's the difference between these two code statements? I'm
convinced they should be the same
type T = [Char]
type CurrentValue = Char
My concern is that in the second one there are no brackets
Anyway they are actually declarations arent'they?
2) What is Maybe String?
For instance: type P = (Char, Maybe String)
Is that a function which has two arguments ?
3) What is Maybe Char ?
For instance : type D = ((Maybe Char) , Char)
It's another function having three arguments..am I right?
Thanks a lot. 777P
--
[email protected]
--
http://www.fastmail.fm - The professional email service
------------------------------
Message: 8
Date: Sat, 2 Jul 2011 11:56:49 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] Understandig types
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
All of your questions are answered very nicely in this tutorial:
> http://learnyouahaskell.com/types-and-typeclasses
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
On Jul 2, 2011, at 11:37 AM, [email protected] wrote:
> Hi everyone. I've got a few questions about the Haskell programming
> language.
>
> 1) what's the difference between these two code statements? I'm
> convinced they should be the same
>
> type T = [Char]
> type CurrentValue = Char
>
> My concern is that in the second one there are no brackets
>
> Anyway they are actually declarations arent'they?
>
> 2) What is Maybe String?
>
> For instance: type P = (Char, Maybe String)
>
> Is that a function which has two arguments ?
>
> 3) What is Maybe Char ?
>
> For instance : type D = ((Maybe Char) , Char)
>
> It's another function having three arguments..am I right?
>
> Thanks a lot. 777P
>
> --
>
> [email protected]
>
>
> --
> http://www.fastmail.fm - The professional email service
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 9
Date: Sat, 02 Jul 2011 09:47:33 -0700
From: [email protected]
Subject: [Haskell-beginners] code explanation
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
I'm a beginner, I'd like someone to help me understand a few
lines of code
My questions are:
1) Maybe String is an application of the constructor Maybe to the
type String.
What does it mean? Is there anything equivalent in the C
language?
2) Is this a function with three arguments?
type T = [Char]
type P = (Char, Maybe String)
type Delta = ((Maybe Char, Char), Maybe String)
fromGtoM :: T -> [P] -> [Delta]
3) is this a usage of the above mentioned function?
fromGtoM t p = terminalRules ++ varRules
I dont'see why the function has three arguments but then only
two are used t p.
4) what does ++ mean ?
Sorry, for posting too many questions.
Thanks in advance.
--
[email protected]
--
http://www.fastmail.fm - Access your email from home and the web
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110702/1f89bd55/attachment-0001.htm>
------------------------------
Message: 10
Date: Sat, 2 Jul 2011 12:54:28 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] code explanation
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
You really, really need to read a basic tutorial. You are not going
to get anywhere in haskell trying to be spoonfed like this.
1) There might be nothing, or their might be a string. No, not really.
2) No.
3) Yes. You will find out within the first five paragraphs of any
haskell tutorial.
4) String concatenation. You will learn how to look up functions in
said tutorial.
On Sat, Jul 2, 2011 at 12:47 PM, <[email protected]> wrote:
> I'm a beginner, I'd like someone to help me understand a few lines of code
> My questions are:
> 1) Maybe String is an application of the constructor Maybe to the type
> String.
> What does it mean? Is there anything equivalent in the C language?
> 2) Is this a function with three arguments?
> type T = [Char]
> type P = (Char, Maybe String)
> type Delta = ((Maybe Char, Char), Maybe String)
> fromGtoM :: T -> [P] -> [Delta]
> 3) is this a usage of the above mentioned function?
> fromGtoM t p = terminalRules ++ varRules
> I dont'see why the function has three arguments but then only
> two are used t p.
> 4) what does ++ mean ?
>
> Sorry, for posting too many questions.
> Thanks in advance.
> --
>
> [email protected]
>
>
> --
> http://www.fastmail.fm - Access your email from home and the web
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 37, Issue 4
****************************************