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: Copy record with mutations? (MAN)
2. How to extract from Maybe & Either in GHCi ([email protected])
3. Re: How to extract from Maybe & Either in GHCi (Benjamin Edwards)
4. Re: How to extract from Maybe & Either in GHCi (Antoine Latter)
5. Re: How to extract from Maybe & Either in GHCi (Daniel Fischer)
6. Re: How to extract from Maybe & Either in GHCi
([email protected])
7. Re: How to extract from Maybe & Either in GHCi (Christopher Done)
----------------------------------------------------------------------
Message: 1
Date: Wed, 13 Apr 2011 18:45:10 -0300
From: MAN <[email protected]>
Subject: Re: [Haskell-beginners] Copy record with mutations?
To: [email protected]
Cc: Andrew n marshall <[email protected]>,
[email protected]
Message-ID: <1302731110.2337.5.camel@dy-book>
Content-Type: text/plain; charset="UTF-8"
Yeah, that's basically it.
Keeping in mind that Haskell's data structures are immutable
"let stang68 = stang67"
allows to use symbol "stang68" as a new Car. Whether an actual copy is
made does not matter: even if both "stang"s point to the same structure
you're not allowed to change its values.
El mi?, 13-04-2011 a las 17:27 +0200, Christopher Done escribi?:
> On 13 April 2011 17:22, Andrew n marshall
> <[email protected]> wrote:
>
> Is there a syntax or function to copy a record, but with
> select fields populated with new values?
>
>
> For example, extending LYAH's Car
> let stang67 = Car {company="Ford", model="Mustang", year=1967}
> let stang68 = stang67 `mutate` Car {year=1968}
>
>
> let stang67 = Car {company="Ford", model="Mustang", year=1967}
> let stang68 = stang67 { year = 1968 }
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Wed, 13 Apr 2011 15:14:19 -0700
From: [email protected]
Subject: [Haskell-beginners] How to extract from Maybe & Either in
GHCi
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
I've got some values in GHCi that look like
Just (Left (Blah [stuff]))
and I'd like to pull out the (Blah [stuff]) to operate on it. Is there
a way to do this directly in GHCi without writing a helper function?
thanks
Lee Short
------------------------------
Message: 3
Date: Wed, 13 Apr 2011 23:19:31 +0100
From: Benjamin Edwards <[email protected]>
Subject: Re: [Haskell-beginners] How to extract from Maybe & Either in
GHCi
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Use the maybe function from Data.Maybe.
maybe :: b -> (a->b) -> Maybe b -> b
On 13 April 2011 23:14, <[email protected]> wrote:
> I've got some values in GHCi that look like
>
> Just (Left (Blah [stuff]))
>
> and I'd like to pull out the (Blah [stuff]) to operate on it. Is there a
> way to do this directly in GHCi without writing a helper function?
>
> thanks
> Lee Short
>
>
> _______________________________________________
> 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/20110413/baae3118/attachment-0001.htm>
------------------------------
Message: 4
Date: Wed, 13 Apr 2011 17:29:15 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] How to extract from Maybe & Either in
GHCi
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
On Wed, Apr 13, 2011 at 5:14 PM, <[email protected]> wrote:
> I've got some values in GHCi that look like
>
> Just (Left (Blah [stuff]))
>
> and I'd like to pull out the (Blah [stuff]) to operate on it. ?Is there a
> way to do this directly in GHCi without writing a helper function?
>
Pattern matching works in ghci:
> let x = Just (Left (Blah [stuff]))
> let (Just (Left (Blah y)) = x
Antoine
> thanks
> Lee Short
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 5
Date: Thu, 14 Apr 2011 00:29:41 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] How to extract from Maybe & Either in
GHCi
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
On Thursday 14 April 2011 00:14:19, [email protected] wrote:
> I've got some values in GHCi that look like
>
> Just (Left (Blah [stuff]))
>
> and I'd like to pull out the (Blah [stuff]) to operate on it. Is there
> a way to do this directly in GHCi without writing a helper function?
I'm not quite sure what you want, you can bind the Blah [stuff] to a name
using a pattern-match, perhaps that's what you want.
After the fact:
ghci> let Just (Left blah) = it
ghci> doSomethingWith blah
or
ghci> case it of Just (Left blah) -> doSomethingWith blah
Before: replace 'it' with the expression generating Just (Left (Blah
[stuff])).
------------------------------
Message: 6
Date: Wed, 13 Apr 2011 15:52:51 -0700
From: [email protected]
Subject: Re: [Haskell-beginners] How to extract from Maybe & Either in
GHCi
To: Antoine Latter <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
> Pattern matching works in ghci:
>
>> let x = Just (Left (Blah [stuff]))
>> let (Just (Left (Blah y)) = x
Thanks! That's exactly what I'm looking for.
------------------------------
Message: 7
Date: Thu, 14 Apr 2011 02:19:15 +0200
From: Christopher Done <[email protected]>
Subject: Re: [Haskell-beginners] How to extract from Maybe & Either in
GHCi
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On 14 April 2011 00:52, <[email protected]> wrote:
> Pattern matching works in ghci:
>>
>> let x = Just (Left (Blah [stuff]))
>>> let (Just (Left (Blah y)) = x
>>>
>>
> Thanks! That's exactly what I'm looking for.
FWIW there is also Data.Either which has the either function.
?> :t either
either :: (a -> c) -> (b -> c) -> Either a b -> c
Quite useful sometimes.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110414/1d19f73b/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 34, Issue 24
*****************************************