Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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. Random variable holding a function (Ondrej Nekola)
2. trees on Haskell : Do I understand it right ? (Roelof Wobben)
3. Re: Random variable holding a function (Daniel Bergey)
4. Re: Random variable holding a function (Daniel Bergey)
5. Re: trees on Haskell : Do I understand it right ?
(Konstantine Rybnikov)
6. Re: trees on Haskell : Do I understand it right ? (Roelof Wobben)
7. Re: trees on Haskell : Do I understand it right ?
(Konstantine Rybnikov)
----------------------------------------------------------------------
Message: 1
Date: Thu, 26 Feb 2015 13:42:03 +0100
From: Ondrej Nekola <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Random variable holding a function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
Hi
I try to simulate some processes, that contain randomness and I would
like do it idiomatic way and keep as much code not to know about
randomness as possible.
I have a following code (simplified to make email more readable):
import Data.List
import Data.Functor
import Genes
import Data.Random.RVar
import Data.Random.Extras
data Individual = Individual (Int, Int) deriving (Eq, Show) -- this part
is a bit more complicated...
data Population = Population { individuals :: [Individual] } deriving
(Eq, Show)
type Selection = Population -> Population
so far, it's easy:
allSurvive :: Selection
allSurvive = id
extinction :: Selection
extinction _ = Population []
The issue comes, when I want to have some randomness in the process. I
am able to write a "pick some individuals into next generation" sort of
"Selection"
fairChance :: Int -> Population -> RVar Population
fairChance newSize p = Population <$> (Data.Random.Extras.sample newSize
$ individuals p)
But it obviously doesn't fit into the "Selection" type. I would like to
have something like
fairChance :: Int -> RVar Selection
(e.g. fairChance :: Int -> RVar (Population -> Population))
Is there a way to do this? Or should I give up this way and try to give
up some purity and go withtype Selection :: RVar Population -> RVar
population?
Thanks
Ondrej
------------------------------
Message: 2
Date: Thu, 26 Feb 2015 14:21:19 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] trees on Haskell : Do I understand it
right ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
Hello,
Suppose we have this definition of a tree :
data MessageTree = Leaf
| Node MessageTree LogMessage MessageTree
deriving (Show, Eq)
let Message = LogMessage "E 1 this is a test error"
let Message = LogMessage "e 2 this is the second test error "
As I understand it right I can make the first entry like this :
first_entry = Node Messagetree Message Messagetree
And the second one like this second_entry = Node Message Messagetree
Message2 Messagetree ??
Roelof
------------------------------
Message: 3
Date: Thu, 26 Feb 2015 13:35:17 +0000
From: Daniel Bergey <[email protected]>
To: Ondrej Nekola <[email protected]>, [email protected]
Subject: Re: [Haskell-beginners] Random variable holding a function
Message-ID: <[email protected]>
Content-Type: text/plain
On 2015-02-26 at 12:42, Ondrej Nekola <[email protected]> wrote:
> type Selection = Population -> Population
>
> so far, it's easy:
>
> allSurvive :: Selection
> allSurvive = id
>
> fairChance :: Int -> Population -> RVar Population
> fairChance newSize p = Population <$> (Data.Random.Extras.sample newSize
> $ individuals p)
>
> fairChance :: Int -> RVar Selection
> (e.g. fairChance :: Int -> RVar (Population -> Population))
>
> Is there a way to do this? Or should I give up this way and try to give
> up some purity and go withtype Selection :: RVar Population -> RVar
> population?
>
> Thanks
> Ondrej
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 4
Date: Thu, 26 Feb 2015 13:40:06 +0000
From: Daniel Bergey <[email protected]>
To: Ondrej Nekola <[email protected]>, [email protected]
Subject: Re: [Haskell-beginners] Random variable holding a function
Message-ID: <[email protected]>
Content-Type: text/plain
On 2015-02-26 at 12:42, Ondrej Nekola <[email protected]> wrote:
> type Selection = Population -> Population
>
> so far, it's easy:
>
> allSurvive :: Selection
> allSurvive = id
>
> fairChance :: Int -> Population -> RVar Population
> fairChance newSize p = Population <$> (Data.Random.Extras.sample newSize
> $ individuals p)
>
> fairChance :: Int -> RVar Selection
> (e.g. fairChance :: Int -> RVar (Population -> Population))
>
> Is there a way to do this? Or should I give up this way and try to give
> up some purity and go withtype Selection :: RVar Population -> RVar
> population?
I would define Selection as
| type Selection = Population -> RVar Population
Then you can compose with >>=, which specializes to
| (>>=) :: RVar Population -> Selection -> RVar Population
or with any of the other Monad operators (eg, >=>).
With this definition, you can keep your current definition of
fairChance.
There's no problem defining values of type `RVar (Population ->
Population`. `fmap allSurvive` is one such. But defining fairChance
this way seems a bit awkward to me.
Daniel
------------------------------
Message: 5
Date: Thu, 26 Feb 2015 15:56:59 +0200
From: Konstantine Rybnikov <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] trees on Haskell : Do I understand it
right ?
Message-ID:
<caabahfqo5o+db_qy_b+vb3e6wwb1bdeqbmpapa6e-5twtje...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi Roelof,
I think you misunderstood it.
There are two things here: types and values (value-constructors). They
exist in different world, not touching each other.
In Haskell, you define a type as:
data <Type_Name> = <ValueConstructor_Name> <Type_Name> <Type_Name>
<Type_Name>
You can create values as:
let varName = <ValueConstructor_Name> <Value> <Value> <Value>
You need to put <Value> of some type, not type name itself in place of
those <Value>s.
So, with datatype you provided, you have two data-constructors:
Leaf
and
Node <val> <val> <val>
You can create a leaf:
let leaf = Leav
or a node:
let node = Node Leaf "msg" Leaf
You can see that Node is a data-constructor that takes 3 values, not
type-names as it's parameters.
Hope this helps.
On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben <[email protected]> wrote:
> Hello,
>
> Suppose we have this definition of a tree :
>
> data MessageTree = Leaf
> | Node MessageTree LogMessage MessageTree
> deriving (Show, Eq)
>
> let Message = LogMessage "E 1 this is a test error"
> let Message = LogMessage "e 2 this is the second test error "
>
> As I understand it right I can make the first entry like this :
> first_entry = Node Messagetree Message Messagetree
>
> And the second one like this second_entry = Node Message Messagetree
> Message2 Messagetree ??
>
> Roelof
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150226/20b806a4/attachment-0001.html>
------------------------------
Message: 6
Date: Thu, 26 Feb 2015 15:01:22 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] trees on Haskell : Do I understand it
right ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150226/5a2528eb/attachment-0001.html>
------------------------------
Message: 7
Date: Thu, 26 Feb 2015 16:08:37 +0200
From: Konstantine Rybnikov <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] trees on Haskell : Do I understand it
right ?
Message-ID:
<caabahfrw8-xtpggs1md5-t4ejqkapsdrd0b4tnqdu0tqzu2...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
In my second example you can see a minimal node with a message:
node = Node Leaf "msg" Leaf
Instead of either left or right Leaf you can put another value of type
MessageTree, for example:
node = Node Leaf "msg1" (Node Leaf "msg2" Leaf)
On Thu, Feb 26, 2015 at 4:01 PM, Roelof Wobben <[email protected]> wrote:
> Oke,
>
> So a leaf is a node which has no "branch"
>
> I have made a exercise where I have to made the logMessages.
> Now I have to turn them into a tree
>
> Where does the second entry goes then ?
>
> Roelof
>
>
> Konstantine Rybnikov schreef op 26-2-2015 om 14:56:
>
> Hi Roelof,
>
> I think you misunderstood it.
>
> There are two things here: types and values (value-constructors). They
> exist in different world, not touching each other.
>
> In Haskell, you define a type as:
>
> data <Type_Name> = <ValueConstructor_Name> <Type_Name> <Type_Name>
> <Type_Name>
>
> You can create values as:
>
> let varName = <ValueConstructor_Name> <Value> <Value> <Value>
>
> You need to put <Value> of some type, not type name itself in place of
> those <Value>s.
>
> So, with datatype you provided, you have two data-constructors:
>
> Leaf
>
> and
>
> Node <val> <val> <val>
>
> You can create a leaf:
>
> let leaf = Leav
>
> or a node:
>
> let node = Node Leaf "msg" Leaf
>
> You can see that Node is a data-constructor that takes 3 values, not
> type-names as it's parameters.
>
> Hope this helps.
>
> On Thu, Feb 26, 2015 at 3:21 PM, Roelof Wobben <[email protected]> wrote:
>
>> Hello,
>>
>> Suppose we have this definition of a tree :
>>
>> data MessageTree = Leaf
>> | Node MessageTree LogMessage MessageTree
>> deriving (Show, Eq)
>>
>> let Message = LogMessage "E 1 this is a test error"
>> let Message = LogMessage "e 2 this is the second test error "
>>
>> As I understand it right I can make the first entry like this :
>> first_entry = Node Messagetree Message Messagetree
>>
>> And the second one like this second_entry = Node Message Messagetree
>> Message2 Messagetree ??
>>
>> Roelof
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
>
> _______________________________________________
> Beginners mailing
> [email protected]http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150226/801f5b26/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 80, Issue 66
*****************************************