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 extend fuinctions? (Heinrich Ody)
2. Use a list as data for a data type? (Bryce Verdier)
3. Re: How to extend fuinctions? (Brent Yorgey)
4. Re: Use a list as data for a data type? (Brent Yorgey)
5. Re: Use a list as data for a data type? (Brent Yorgey)
6. Re: Use a list as data for a data type? (Bryce Verdier)
7. Re: Use a list as data for a data type? (Michael Orlitzky)
8. Re: Beginners Digest, Vol 56, Issue 33 (xiao Ling)
----------------------------------------------------------------------
Message: 1
Date: Fri, 22 Feb 2013 18:35:19 +0100
From: Heinrich Ody <[email protected]>
Subject: [Haskell-beginners] How to extend fuinctions?
To: [email protected]
Message-ID:
<CAMc+G-=RU333QXTZCuqHs+J1hpsHHpO=lr9mqpa9_z7-kl0...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
I have a function Delta and two sets S and A. Delta maps some elements
from (S x A) to S.
How can I extend Delta to some Delta' such that it assigns to every
pair in (S x A) that Delta is not defined for a value not occuring in
S?
Something like:
Delta' = if (Delta s a) /= _Undefined_
then Delta s a
else if () n
where n is the new value.
However Delta' should not assign values to pairs not in (S x A).
Note: (S x A) is meant to be the set-crossprroduct.
Background: I want to learn Haskell by building a small library for
Finite State Automata, B?chi Automata etc. I need this extension of
Delta for making automata complete.
Regards and thanks for reading,
Heinrich
------------------------------
Message: 2
Date: Fri, 22 Feb 2013 10:43:32 -0800
From: Bryce Verdier <[email protected]>
Subject: [Haskell-beginners] Use a list as data for a data type?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Lets say I have a data type like so:
data IpAddress = IpAddress {$
o1 :: !Int,$
o2 :: !Int,$
o3 :: !Int,$
o4 :: !Int$
} deriving (Show)$
which you can create by doing:
IpAddress 192 168 1 1
Is there a way to do the same thing with the input data in a list? Like:
IpAddress [192,168,1,1]
or using some operator (or combination of operators):Like (I'm guessing
(<????>) isn't in use):
IpAddress <????> [192,168,1,1]
Thanks in advance,
Bryce
------------------------------
Message: 3
Date: Fri, 22 Feb 2013 14:06:36 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] How to extend fuinctions?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Feb 22, 2013 at 06:35:19PM +0100, Heinrich Ody wrote:
> Hi,
>
> I have a function Delta and two sets S and A. Delta maps some elements
> from (S x A) to S.
> How can I extend Delta to some Delta' such that it assigns to every
> pair in (S x A) that Delta is not defined for a value not occuring in
> S?
If your function delta is partial, then you should model this in
Haskell by having it return a Maybe, i.e.
delta :: S -> Maybe A
Then you can define delta' like this:
delta' s a = case delta s a of
Nothing -> n
Just x -> x
If your function delta really is partial in Haskell (i.e. it sometimes
crashes or returns 'undefined') then you cannot implement delta',
because there is no way to check whether a function returns undefined.
It is not a good idea to have partial functions in Haskell anyway.
-Brent
------------------------------
Message: 4
Date: Fri, 22 Feb 2013 14:07:43 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Use a list as data for a data type?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Feb 22, 2013 at 10:43:32AM -0800, Bryce Verdier wrote:
> Lets say I have a data type like so:
>
> data IpAddress = IpAddress {$
> o1 :: !Int,$
> o2 :: !Int,$
> o3 :: !Int,$
> o4 :: !Int$
> } deriving (Show)$
>
> which you can create by doing:
> IpAddress 192 168 1 1
>
> Is there a way to do the same thing with the input data in a list? Like:
> IpAddress [192,168,1,1]
>
> or using some operator (or combination of operators):Like (I'm
> guessing (<????>) isn't in use):
> IpAddress <????> [192,168,1,1]
No, there isn't. But you can make a function
ipAddress :: [Int] -> IpAddress
ipAddress [a,b,c,d] = IpAddress a b c d
-Brent
------------------------------
Message: 5
Date: Fri, 22 Feb 2013 15:14:33 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Use a list as data for a data type?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Feb 22, 2013 at 02:07:43PM -0500, Brent Yorgey wrote:
> On Fri, Feb 22, 2013 at 10:43:32AM -0800, Bryce Verdier wrote:
> > Lets say I have a data type like so:
> >
> > data IpAddress = IpAddress {$
> > o1 :: !Int,$
> > o2 :: !Int,$
> > o3 :: !Int,$
> > o4 :: !Int$
> > } deriving (Show)$
> >
> > which you can create by doing:
> > IpAddress 192 168 1 1
> >
> > Is there a way to do the same thing with the input data in a list? Like:
> > IpAddress [192,168,1,1]
> >
> > or using some operator (or combination of operators):Like (I'm
> > guessing (<????>) isn't in use):
> > IpAddress <????> [192,168,1,1]
>
> No, there isn't. But you can make a function
>
> ipAddress :: [Int] -> IpAddress
> ipAddress [a,b,c,d] = IpAddress a b c d
For that matter you can define the operator (<????>) yourself:
(<????>) :: (a -> a -> a -> a -> b) -> [a] -> b
f <????> [a,b,c,d] = f a b c d
Not sure how useful it is though.
-Brent
------------------------------
Message: 6
Date: Fri, 22 Feb 2013 12:40:15 -0800
From: Bryce Verdier <[email protected]>
Subject: Re: [Haskell-beginners] Use a list as data for a data type?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Brent,
Thank you for the responses. I appreciate it. Bummer about there not
being some kind of built-in/generic shortcut.
Bryce
On 02/22/2013 12:14 PM, Brent Yorgey wrote:
> On Fri, Feb 22, 2013 at 02:07:43PM -0500, Brent Yorgey wrote:
>> On Fri, Feb 22, 2013 at 10:43:32AM -0800, Bryce Verdier wrote:
>>> Lets say I have a data type like so:
>>>
>>> data IpAddress = IpAddress {$
>>> o1 :: !Int,$
>>> o2 :: !Int,$
>>> o3 :: !Int,$
>>> o4 :: !Int$
>>> } deriving (Show)$
>>>
>>> which you can create by doing:
>>> IpAddress 192 168 1 1
>>>
>>> Is there a way to do the same thing with the input data in a list? Like:
>>> IpAddress [192,168,1,1]
>>>
>>> or using some operator (or combination of operators):Like (I'm
>>> guessing (<????>) isn't in use):
>>> IpAddress <????> [192,168,1,1]
>> No, there isn't. But you can make a function
>>
>> ipAddress :: [Int] -> IpAddress
>> ipAddress [a,b,c,d] = IpAddress a b c d
> For that matter you can define the operator (<????>) yourself:
>
> (<????>) :: (a -> a -> a -> a -> b) -> [a] -> b
> f <????> [a,b,c,d] = f a b c d
>
> Not sure how useful it is though.
>
> -Brent
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 7
Date: Fri, 22 Feb 2013 15:56:51 -0500
From: Michael Orlitzky <[email protected]>
Subject: Re: [Haskell-beginners] Use a list as data for a data type?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 02/22/2013 03:40 PM, Bryce Verdier wrote:
> Brent,
>
> Thank you for the responses. I appreciate it. Bummer about there not
> being some kind of built-in/generic shortcut.
>
You can try with a fold:
>>> (((IpAddress $ 1) $ 2) $ 3) $ 4
IpAddress 1 2 3 4
If you consider the type of the constructor along with the types passed
through the fold, it might become clearer why this can't work in general.
------------------------------
Message: 8
Date: Fri, 22 Feb 2013 19:27:28 -0500
From: xiao Ling <[email protected]>
Subject: Re: [Haskell-beginners] Beginners Digest, Vol 56, Issue 33
To: [email protected]
Message-ID:
<cah2t2p9bqqxmas4ozh4afvjyssfy430q3+ff8oyazn2t1sk...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi All: How do you define a function of signature h :: M Int -> M Int -> M
Int so that h ( M x ) ( M y ) = M ( x + y ), but without unwrapping the
value from the monad?
This question is from the article "Trivial Monad" found at
http://blog.sigfpe.com/2007/04/trivial-monad.html. The provided answer is
h x y = x >>= (\x -> g x y)
or equivalently ( in context of the article )
h :: M Int -> M Int -> M Int
h x y = bind ( \x-> g x y ) x
where g is
g :: Int -> W Int -> W Int
g x y = y >>= (return . (+x))
for the monad:
data M a = M a deriving Show
Now I am a little confused, how can you put x in g if it takes an Int as
first parameter but x is M Int?
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130222/1e237638/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 56, Issue 37
*****************************************