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. hanoi 4 problem (Roelof Wobben)
2. enumaratioin question (Roelof Wobben)
3. Re: enumaratioin question (Leza Morais Lutonda)
4. Re: enumaratioin question
(Sumit Sahrawat, Maths & Computing, IIT (BHU))
5. Re: Package access problem ([email protected])
6. Re: enumaratioin question (Roelof Wobben)
----------------------------------------------------------------------
Message: 1
Date: Thu, 19 Feb 2015 14:50:10 +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] hanoi 4 problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
Hello,
I try now to make the optional exercise hanoi with 4 pegs,
So I did on paper this :
start temp1 temp2 end
3
2
1
first move : start -> temp2
start temp1 temp2 end
2 3
1
second move : start -> temp1
start temp1 temp2 end
1 2 3
now I tried to make this piece in code
So I did :
hanoi4 1 start _ _ end = "move 1 disk from " ++ [start] ++ " to " ++
[end] ++ ".\n"
hanoi4 n start temp1 temp2 end = hanoi4 (n-1) start end temp1 temp2 ++
hanoi4 1 start end temp1 temp2 ++ hanoi4 (n-1) start temp1 end temp2
because on the first step start must be start and end must be temp1
and on the second step start must be start and end must be temp2
but when I run in I see this output :
move 1 disk from a to b.
move 1 disk from a to b.
move 1 disk from a to b.
move 1 disk from a to c.
move 1 disk from a to d.
move 1 disk from a to d.
move 1 disk from a to d.
Can anyone explain or let me see where my thinking took the wrong turn ?
Roelof
------------------------------
Message: 2
Date: Thu, 19 Feb 2015 17:28:47 +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] enumaratioin question
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150219/6510125d/attachment-0001.html>
------------------------------
Message: 3
Date: Thu, 19 Feb 2015 11:36:51 -0500
From: Leza Morais Lutonda <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] enumaratioin question
Message-ID: <[email protected]>
Content-Type: text/plain; charset="windows-1252"; Format="flowed"
Maybe you will want this:
data Person = Person {
name :: String,
age :: Int,
favThing :: String
}
And get the age:
getAge :: Person -> Int
getAge p = age p
Or better:
getAge = age
On 02/19/2015 11:28 AM, Roelof Wobben wrote:
> Hello,
>
> Im reading chapter 2 of the CIS 194 course about enumaratuin.
>
> Now they give this example :
>
> |-- Store a person's name, age, and favourite Thing.
> data Person = Person String Int Thing
> deriving Show
>
> brent :: Person
> brent= Person "Brent" 31 SealingWax
>
> stan :: Person
> stan= Person "Stan" 94 Cabbage
>
> getAge :: Person -> Int
> getAge (Person _ a _)= a
>
> I understand how this works.
>
> But I wonder if there is no "better" way to get the Age.
>
> Is it now wise to make a person data like this :
>
> data Person = Name : String
> | Age : Integer
> | FavThing : String
>
> And if so , how can I get the age then ?
>
> Roelof
>
>
> |
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
50 Aniversario de la Cujae. Inaugurada por Fidel el 2 de diciembre de 1964
http://cujae.edu.cu
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150219/83599eb3/attachment-0001.html>
------------------------------
Message: 4
Date: Thu, 19 Feb 2015 22:07:58 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
<[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] enumaratioin question
Message-ID:
<CAJbEW8McB7=yzdyqxxlqs_pne242snb+yacvwwefwpp9twc...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I can't understand what you mean by those colons in the second definition
of Person. If you're thinking of type signatures, then that doesn't work in
haskell.
In an ADT, you give names to possible values. So "Name String" will work
whereas "Name : String" won't work.
data Person = Name String
| Age Integer
| FavThing String
means that Person can be *one of* these things (which is not what you want).
What you want is possible with record syntax. He'll detail it later I think.
If you're interested in learning about it beforehand, look it up in the
haskell wikibook (another great haskell resource).
More about ADTs in general:
http://en.wikibooks.org/wiki/Haskell/Type_declarations#data_and_constructor_functions
The link to the specific section:
http://en.wikibooks.org/wiki/Haskell/More_on_datatypes#Named_Fields_.28Record_Syntax.29
On 19 February 2015 at 21:58, Roelof Wobben <[email protected]> wrote:
> Hello,
>
> Im reading chapter 2 of the CIS 194 course about enumaratuin.
>
> Now they give this example :
>
> -- Store a person's name, age, and favourite Thing.data Person = Person
> String Int Thing
> deriving Show
> brent :: Person
> brent = Person "Brent" 31 SealingWax
> stan :: Person
> stan = Person "Stan" 94 Cabbage
> getAge :: Person -> Int
> getAge (Person _ a _) = a
>
> I understand how this works.
>
> But I wonder if there is no "better" way to get the Age.
>
> Is it now wise to make a person data like this :
>
> data Person = Name : String
> | Age : Integer
> | FavThing : String
>
> And if so , how can I get the age then ?
>
> Roelof
>
>
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
--
Regards
Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150219/1d13ccc5/attachment-0001.html>
------------------------------
Message: 5
Date: Thu, 19 Feb 2015 11:38:21 -0500
From: [email protected]
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Package access problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
It looks like OP tried doing ":m + Diagrams.Prelude" already...
El Feb 18, 2015, a las 8:23, Daniel Bergey <[email protected]> escribi?:
> On 2015-02-18 at 02:15, Brandon Allbery <[email protected]> wrote:
>> On Tue, Feb 17, 2015 at 9:13 PM, Gregory Guthrie <[email protected]> wrote:
>>
>>> <no location info>:
>>>
>>> Could not find module `Diagrams'
>> "Diagrams" is not a module in any of the packages; it's just a point in the
>> namespace under which the actual modules reside. I see for example at
>> http://hackage.haskell.org/package/diagrams-core
>
> Expanding on Brandon's answer, Diagrams.Prelude[1] is probably what you
> want to import. You'll also need one of the Backends, to save files.
> See for instance this minimal example: [2]
>
> Footnotes:
> [1]
> http://hackage.haskell.org/package/diagrams-lib-1.2.0.8/docs/Diagrams-Prelude.html
>
> [2] http://projects.haskell.org/diagrams/doc/manual.html#getting-started
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 6
Date: Thu, 19 Feb 2015 17:57:54 +0100
From: Roelof Wobben <[email protected]>
To: [email protected], The Haskell-Beginners Mailing
List - Discussion of primarily beginner-level topics related to
Haskell <[email protected]>
Subject: Re: [Haskell-beginners] enumaratioin question
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150219/75d6c49c/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 52
*****************************************