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. don't understand this (Roelof Wobben)
2. Re: A first try (David Place)
3. Re: don't understand this (Mats Rauhala)
4. Re: don't understand this (Mats Rauhala)
5. Re: A first try (Heinrich Apfelmus)
6. Re: don't understand this (Roelof Wobben)
7. Re: don't understand this (Ozgur Akgun)
8. Re: A first try (David Place)
9. Re: A first try (Manfred Lotz)
10. DSL for Android development (Sean Charles)
----------------------------------------------------------------------
Message: 1
Date: Mon, 27 Jun 2011 12:47:20 +0000
From: Roelof Wobben <[email protected]>
Subject: [Haskell-beginners] don't understand this
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hello,
I must find the k st number in a list.
So I have this list [1,2,3,4] and I have to find the second number.
According to the solution the answer is :
elementAt list i = list !! (i-1)
But where do I fill in [1,2,3,4] and the 2 ?
Roelof
------------------------------
Message: 2
Date: Mon, 27 Jun 2011 08:47:53 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] A first try
To: [email protected]
Cc: Heinrich Apfelmus <[email protected]>,
[email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jun 27, 2011, at 8:33 AM, Yitzchak Gale wrote:
> David Place wrote:
>> Suppose the file is only partially demanded as in the case I quoted earlier.
>>
>> print10 =
>> do
>> contents <- withFile "/usr/share/dict/words" ReadMode (\h ->
>> hGetContents h)
>> print $ take 10 contents
>>
>> The file would never be closed.
>
> I tried it - it does close the file.
>
> Thanks,
> Yitz
II'm not sure what you mean. Did you create a new version of withFile that
behaves as Heinrich suggested? If so, please post its definition.
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
------------------------------
Message: 3
Date: Mon, 27 Jun 2011 15:58:53 +0300
From: Mats Rauhala <[email protected]>
Subject: Re: [Haskell-beginners] don't understand this
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On 12:47 Mon 27 Jun , Roelof Wobben wrote:
>
> Hello,
>
> I must find the k st number in a list.
> So I have this list [1,2,3,4] and I have to find the second number.
> According to the solution the answer is :
> elementAt list i = list !! (i-1)
>
> But where do I fill in [1,2,3,4] and the 2 ?
If you are unclear about a function, load it up in ghci and check it's
type signature, it can tell you much. The type for elementAt is `[a] ->
Int -> a` which tells you that the first argument is the list and the
second argument is the kth. Actually you can see that also from the
variable names, just replace 'kth' with 'ith'.
The function (!!) is an infix function, meaning that it can be used
between two parameters, but when reading the type signature, it's easier
to think of it as a normal function. The type signature for (!!) is `[a]
-> Int -> a` which means that the first argument is a list and the
second is the index. The functions fetches the item from a list at a
given 0-based index.
--
Mats Rauhala
MasseR
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110627/167b6c9c/attachment-0001.pgp>
------------------------------
Message: 4
Date: Mon, 27 Jun 2011 16:00:23 +0300
From: Mats Rauhala <[email protected]>
Subject: Re: [Haskell-beginners] don't understand this
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Sorry for the doublepost.
You should also check out the Learn you a haskell book from
http://learnyouahaskell.com which you can read on the internet for free.
The first few chapters teach you these exact things you've been asking
here.
--
Mats Rauhala
MasseR
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110627/12397079/attachment-0001.pgp>
------------------------------
Message: 5
Date: Mon, 27 Jun 2011 15:32:37 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: Re: [Haskell-beginners] A first try
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
David Place wrote:
> On Jun 27, 2011, at 3:50 AM, Heinrich Apfelmus wrote:
>
>> Good point, but this actually shows that withFile should be even lazier.
>> In particular:
>>
>> * The file should not be opened until the string is demanded.
>> * The file should be closed as soon as the string has been demanded in full.
>
> Suppose the file is only partially demanded as in the case I quoted earlier.
>
> print10 =
> do
> contents <- withFile "/usr/share/dict/words" ReadMode (\h ->
> hGetContents h)
> print $ take 10 contents
>
> The file would never be closed.
Note that my version of withFile has a different type and replaces
hGetContents entirely.
Regardless, in both cases the intention is that the file contents is
evaluated completely *inside* the scope of withFile . In particular, a
correct way to write your example would be
print10 = withFile' "/usr/share/dict/words" $ print . take 10
(This is completely analogous to how Iteratees require you to process a
file. The difference is that Iteratees expresses demand for the
characters inside a file via >>= whereas lazy IO expresses demand via
`seq` .)
Best regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 6
Date: Mon, 27 Jun 2011 13:33:34 +0000
From: Roelof Wobben <[email protected]>
Subject: Re: [Haskell-beginners] don't understand this
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
hello,
Im reading that book and im now reading chapter4.
Where I don't get this :
You have this :
lucky 7 = "LUCKY NUMBER SEVEN!"
lucky x = "Sorry, you're out of luck, pal!"
So I entered these lines with let for it.
So let lucky 7 = "Lucky number seven"
let lucky x = "Sorry, you're out of luck, pal!"
But if I do lucky 7 or lucky 2 I always get the last sentence.
Roelof
----------------------------------------
Date: Mon, 27 Jun 2011 16:00:23 +0300
From: [email protected]
To: [email protected]
Subject: Re: [Haskell-beginners] don't understand this
Sorry for the doublepost.
You should also check out the Learn you a haskell book from
http://learnyouahaskell.com which you can read on the internet for free.
The first few chapters teach you these exact things you've been asking
here.
--
Mats Rauhala
MasseR
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 7
Date: Mon, 27 Jun 2011 16:43:56 +0300
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] don't understand this
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi.
On 27 June 2011 16:33, Roelof Wobben <[email protected]> wrote:
> let lucky 7 = "Lucky number seven"
> let lucky x = "Sorry, you're out of luck, pal!"
>
> But if I do lucky 7 or lucky 2 I always get the last sentence.
>
The second let binding shadows the first one. Try:
let lucky 7 = "Lucky!"; lucky x = "No luck this time."
Or even better, write this in a file and load it into ghci.
lucky 7 = "Lucky!"
lucky x = "No luck this time."
HTH,
Ozgur
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110627/65246b28/attachment-0001.htm>
------------------------------
Message: 8
Date: Mon, 27 Jun 2011 09:48:00 -0400
From: David Place <[email protected]>
Subject: Re: [Haskell-beginners] A first try
To: Heinrich Apfelmus <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Jun 27, 2011, at 9:32 AM, Heinrich Apfelmus wrote:
> Note that my version of withFile has a different type and replaces
> hGetContents entirely.
>
> Regardless, in both cases the intention is that the file contents is
> evaluated completely *inside* the scope of withFile . In particular, a
> correct way to write your example would be
>
> print10 = withFile' "/usr/share/dict/words" $ print . take 10
>
> (This is completely analogous to how Iteratees require you to process a file.
> The difference is that Iteratees expresses demand for the characters inside a
> file via >>= whereas lazy IO expresses demand via `seq` .)
So, the type of your withFile would be
withFile :: FilePath -> IOMode -> (Handle -> IO ()) -> IO ()
completely prohibiting return values from withFile? Sounds good. In that
case, you don't need to change the behavior of withFile at all, just its type.
It's hGetContents that bothers me. I have found that friends who I have
convinced to learn Haskell always trip over this right away. They want to
write a simple program that processes a file and immediately get tangled up
with lazy IO and looking up the definition of deepseq. It's kind of
embarrassing. Sadly, they never pick creating beautiful, incremental lazy
algorithms with sharing as their "Hello World" projects.
____________________
David Place
Owner, Panpipes Ho! LLC
http://panpipesho.com
[email protected]
------------------------------
Message: 9
Date: Mon, 27 Jun 2011 15:58:48 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] A first try
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
On Mon, 27 Jun 2011 11:49:37 +0200
Daniel Fischer <[email protected]> wrote:
> On Monday 27 June 2011, 11:15:13, Manfred Lotz wrote:
> >
> > I tried now:
> >
> > getXmlContent :: String -> Handle -> IO Ctan
> > getXmlContent xf inh = do
> > xml <- U.hGetContents inh
> > let content = xml `deepseq` parseXMLDoc xml
> > case content of
> > ...
> >
> > deepseq really ensures parseXmlDoc gets the full file as a string.
> >
> > It is unclear to me how this could be done without deepseq.
>
> To ensure that the entire file is read, you can seq on the length,
>
> xml <- U.hGetContents inh
> let content = parseXMLDoc xml
> length xml `seq` case content of ...
>
Thanks a lot for the suggestion. Works fine.
I only tried deepseq because my first try with seq
let content = xml `seq` parseXMLDoc xml
didn't work.
--
Manfred
------------------------------
Message: 10
Date: Mon, 27 Jun 2011 15:04:55 +0100
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] DSL for Android development
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
As a yet to be published iPhone hacker, now somewhat saddened by the
AppStore bouncers, I've turned to Android. I have a lot of Java and J2ME
experience but only eight months with Haskell. I hate java. The JVM is
awesome. Clojure is wish-fulfillment for Android right now.
Having used Chicken (scheme) in the past for generating applications for
people I know that compiling language A to language B can be very
successful, especially when the end-user doesn't know or care how he got
his app, only that it works.
So... where would be a good place to start with a DSL that could produce
Java code as its output? This is new to me! I've written simple lexers
and parsers and I know the ropes on that front but I don't know haskell
well enough yet to know how to go about it. I am thinking that I'd need
to create data types for the major classes, or maybe not, if i can
produce my own abstraction that generated multiple classes in the output
etc and so i descend into confusion about where to start!
I suspect that state carrying monadic types will be prevalent, good job
I understand monads. Yes that was sarcasm. I've done the Scheme-in-48
hours thing, so I am ok with parsec. I did consider writing a "true"
language that will code-generate java instead of a DSL, that's still in
my mind too.
As I understand DSL, it's up to me to invent my language to work within
the "domain" of Android and then make it create Java code for subsequent
feeding to the android tools. As a first guess, I am going to study the
"Hello Android" example and then see how I could create a DSL around
that little program.
As I see it, programming boils down to just a couple of things: function
calls and decisions. I appreciate that there is more to it: XML files
and images etc to be bound in but that's nothing a good bash script
won't fix for me!
Thanks,
Sean Charles.
PS: I know this is a *big* thing to take on but I love big and I love
learning so let's rip this one to bits.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20110627/d07aa0d3/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 36, Issue 72
*****************************************