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: Re: Defining 'words' in terms of 'span' (Daniel Fischer)
2. Re: Reading in the contents of a variable number of files
(Daniel Fischer)
3. Re: Re: Defining 'words' in terms of 'span' (Roger Whittaker)
4. Re: generating by mapping (Ozgur Akgun)
5. about installation of Haskell (love_pku)
6. Re: about installation of Haskell (aditya siram)
7. Re: about installation of Haskell (Tim Perry)
8. Re: about installation of Haskell (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Tue, 16 Mar 2010 22:22:23 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Re: Defining 'words' in terms of
'span'
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Dienstag 16 März 2010 21:54:24 schrieb Tim Attwood:
> "Roger Whittaker" <[email protected]> wrote in message
> news:[email protected]...
>
> >I found some exam papers linked from this page:
> > http://www.cs.chalmers.se/Cs/Grundutb/Kurser/d1pt/d1pta/external.html
> >
> > And I have been trying some questions from them.
> >
> > I'm currently baffled by question 2(b) on this one:
> > http://www.cs.chalmers.se/Cs/Grundutb/Kurser/d1pt/d1pta/tenta2000-04.p
> >s
> >
> > A word is a sequence of alphabetic characters, which you can
> > recognise using the standard function
> >
> > isAlpha :: Char -> Bool
> >
> > Using span, define a function words :: String -> [String] which
> > finds a list of the words occurring in a string. For example,
> >
> > words "Now is the winter of our discontent!"
> > == ["Now","is","the","winter","of","our","discontent"]
> >
> > words "2+3" == []
> >
> > words "1 by 1" == ["by"]
> >
> > Can anyone give me a clue how to start?
>
> words' = filter (all isAlpha) . words
Prelude> words' "Now is the winter of our discontent!"
["Now","is","the","winter","of","our"]
Maybe you thought of
words'' = map (filter isAlpha) . words
, but that doesn't do the required thing for e.g.
"oops,forgot the space after the comma!"
>
> ...but since they specifically want span in the answer I'd guess they
> want some sort of recursive function
Sure. At the bottom, such a function must use recursion. The question is,
can you employ some combinators like fold*, or do you have to recur
explicitly.
>
> words' s = wGen s [] where
> wGen s a =
> let (n,ws) = span (\x -> not (isAlpha x)) s
> (w,ss) = span (isAlpha) ws
> in case (w=="",ss="") of
> True, _ -> reverse a
> False, True -> reverse (w:a)
> False, False -> wGen ss (w:a)
>
> something ugly like that maybe.
>
More like
words' s = case span isAlpha (dropWhile (not . isAlpha) s) of
("",_) -> []
(w,rest) -> w:words' rest
------------------------------
Message: 2
Date: Tue, 16 Mar 2010 22:28:55 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Reading in the contents of a variable
number of files
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Dienstag 16 März 2010 22:10:46 schrieb Tim Perry:
> I need to read in and then combine a variable number of files. I am
> trying to figure out how to get the contents of all the files into an
> array.
>
> let fileContentsArray = getData ["dataFile1.txt",
> "dataFile2.txt"]
>
> getData :: [String] -> [String]
> getData [] = []
> getData (f:files) = do
> fileData
> <- readFile f
> fileData : (getData files)
>
> I figured I could use readFile to open the files. But, I need to use
> <- to get the data out of the IO Action and into a value. I thought I
> could write a function like the following, but I'm getting no-where. I
> suspect I'm missing something basic about IO in Haskell. Can anybody
> point me to a good resource....
If you're in IO, you can't get out (well, you can, but you shouldn't unless
you really know what you do, the first six letters of unsafePerformIO
really mean what they say).
Is
do some stuff
more stuff
fileContentsList <- mapM readFile ["dataFile1.txt","dataFile2.txt"]
print $ use fileContentsList other things
with an IO-free use function an option?
>
> Thanks,
> Tim
------------------------------
Message: 3
Date: Tue, 16 Mar 2010 22:02:01 +0000
From: Roger Whittaker <[email protected]>
Subject: Re: [Haskell-beginners] Re: Defining 'words' in terms of
'span'
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Thanks for the suggestions - I think the idea was that you had to
use a recursive definition in terms of span.
I eventually did this, but didn't feel it was at all nice or
elegant:
import Data.Char
mywords :: [Char] -> [[Char]]
mywords l | ((snd (span isAlpha l)) == "" && (fst (span isAlpha l)) == "") = []
| ((snd (span isAlpha l)) == "" && (fst (span isAlpha l)) /= "") =
[fst (span isAlpha l)]
| (fst (span isAlpha l)) == "" = mywords (tail (snd (span isAlpha
l)))
| otherwise = [fst (span isAlpha l)] ++ mywords (tail (snd (span
isAlpha l)))
--
========================
Roger Whittaker
[email protected]
http://disruptive.org.uk
========================
------------------------------
Message: 4
Date: Tue, 16 Mar 2010 23:31:21 +0000
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] generating by mapping
To: Tim Perry <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
If you're ready to write a lambda expression why not you just say:
zipWith (\ x y -> Stuff x y ) nums strs
Yet now this one naturally reduces to Stephen's version. Go with that one :)
On Tuesday, March 16, 2010, Tim Perry <[email protected]> wrote:
>
> Stephen's version is cleaner, but this works too:
> map (\(x, y) -> Stuff x y) $ zip nums strs
>
>
>
>
> ----- Original Message ----
> From: Stephen Tetley <[email protected]>
> To: Szilveszter Juhos <[email protected]>
> Cc: [email protected]
> Sent: Tue, March 16, 2010 2:09:51 AM
> Subject: Re: [Haskell-beginners] generating by mapping
>
> Hi Szilveszter
>
> zipWith is probably what you are after...
>
>> zipWith Stuff nums strs
> [Stuff {aNum = 123, anStr = "qwe"},Stuff {aNum = 321, anStr =
> "asd"},Stuff {aNum = 345, anStr = "zxc
> "}]
>
> Note zipWith (and the function zip which it generalizes) go 'short' -
> i.e. if one of the input lists is shorter than the other - the size of
> the result list will the size of of the shorter one:
>
>
>> zipWith Stuff [1] strs
> [Stuff {aNum = 1, anStr = "qwe"}]
>
>
> Best wishes
>
> Stephen
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Ozgur Akgun
------------------------------
Message: 5
Date: Wed, 17 Mar 2010 10:03:30 +0800 (CST)
From: love_pku <[email protected]>
Subject: [Haskell-beginners] about installation of Haskell
To: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="gbk"
Dear Sir or Madam::
Sorry to trouble you!
I am a beginner of Haskell and I just run into problems to install it. So I
hope if you can tell me which version of Haskell should I use for Ubuntu 8.04
operating system..
Thank you very much!
Best wishes,
Yours juan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100316/5c36624b/attachment-0001.html
------------------------------
Message: 6
Date: Tue, 16 Mar 2010 22:21:25 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] about installation of Haskell
To: love_pku <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
You can use GHC 6.10.4 [1] and Haskell Platform [2]. Instructions on
how to install Haskell Platform on Ubuntu are available at its home
page [3].
What problems are you currently having?
-deech
[1]
http://www.haskell.org/ghc/dist/6.10.4/ghc-6.10.4-i386-unknown-linux-n.tar.bz2
[2]
http://hackage.haskell.org/platform/2009.2.0.2/haskell-platform-2009.2.0.2.tar.gz
[3] http://hackage.haskell.org/platform/
On 3/16/10, love_pku <[email protected]> wrote:
>
>
>
>
> Dear Sir or Madam::
>
> Sorry to trouble you!
>
> I am a beginner of Haskell and I just run into problems to install it. So
> I hope if you can tell me which version of Haskell should I use for Ubuntu
> 8.04 operating system..
>
> Thank you very much!
>
> Best wishes,
>
>
>
>
>
> Yours juan
------------------------------
Message: 7
Date: Tue, 16 Mar 2010 20:28:24 -0700 (PDT)
From: Tim Perry <[email protected]>
Subject: Re: [Haskell-beginners] about installation of Haskell
To: love_pku <[email protected]>, "[email protected]"
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
I'd recommend ghc, not because its the best distribution, but because
its the only one I've used.
Here are the simplest directions I
could find that seemed correct:
http://www.mickinator.com/wordpress/?p=31
I'm sure there are directions for hugs, but I haven't used hugs on Ubuntu.
Good luck,
Tim
________________________________
From: love_pku <[email protected]>
To: "[email protected]" <[email protected]>
Sent: Tue, March 16, 2010 7:03:30 PM
Subject: [Haskell-beginners] about installation of Haskell
Dear Sir or Madam::
Sorry to trouble you!
I am a beginner of Haskell and I just run into problems to install it. So I
hope if you can tell me which version of Haskell should I use for Ubuntu 8.04
operating system..
Thank you very much!
Best wishes,
Yours juan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100316/c11f15bc/attachment-0001.html
------------------------------
Message: 8
Date: Wed, 17 Mar 2010 04:39:03 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] about installation of Haskell
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Am Mittwoch 17 März 2010 03:03:30 schrieb love_pku:
> Dear Sir or Madam::
>
> Sorry to trouble you!
>
> I am a beginner of Haskell and I just run into problems to install it.
> So I hope if you can tell me which version of Haskell should I use for
> Ubuntu 8.04 operating system..
I'm not familiar with Ubuntu, but
apt-get install libghc6*
or something like that should get you started (perhaps apt-search haskell
first - or was it apt-get search?).
Once you have GHC installed, you can start.
You'll probably want cabal-install to easily get and build Haskell
libraries, so go to
http://hackage.haskell.org/package/cabal-install
and download a tarball. Depending on the GHC version apt-get gives you,
you'd want different versions of cabal-install.
6.12.1 -> 0.8.0,
6.10.* -> 0.6.*,
6.8.* -> 0.5.*,
I think. (If it's 6.8.*, maybe you want to get a newer GHC from
http://haskell.org/ghc/download.html)
Run 'ghc-pkg list' to find out which version of the Cabal (uppercase C)
library came with your GHC, and search the cabal-install packages for
corresponding constraints on Cabal.
Download that version, unpack it. In the unpacked directory, run
bootstrap.sh and you should have everything you need to start happy Haskell
hacking :D
>
> Thank you very much!
>
> Best wishes,
>
>
>
>
>
> Yours juan
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 21, Issue 18
*****************************************