Parse error: naked expression at top level
 
            Hello, I made this little script : replicate :: Int -> a -> [a] replicate a xs = [xs | x' <= a <--xs] replicate 3 True But when I let it run in GHCi, version 7.0.3 on a FreeBSD box I see this error : oefening.hs:4:1: Parse error: naked expression at top level Failed, modules loaded: none. How can I solve this and what does it mean. Roelof
 
            On Wed, Jul 20, 2011 at 11:30, Roelof Wobben 
replicate :: Int -> a -> [a] replicate a xs = [xs | x' <= a <--xs]
replicate 3 True
That last line is fine at a GHCi prompt but not in a program. (Files loaded by ghci are not scripts! They are treated the same way as program files fed to ghc or runhaskell.) -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
 
            Oke, 
So  In the file I have to load I must put the first 2 lines.
And in the prompt I have to do the last line,
Or is there a way I can use all three lines in a file ?
Roelof
Date: Wed, 20 Jul 2011 11:47:51 -0400
Subject: Re: [Haskell-beginners] Parse error: naked expression at top level
From: allbery.b@gmail.com
To: rwobben@hotmail.com
CC: beginners@haskell.org
On Wed, Jul 20, 2011 at 11:30, Roelof Wobben 
 
            On Wed, Jul 20, 2011 at 10:50 AM, Roelof Wobben 
Oke,
So In the file I have to load I must put the first 2 lines. And in the prompt I have to do the last line,
Or is there a way I can use all three lines in a file ?
Roelof
You could say:
x = replicate 3 True
or:
main = print (replicate 3 True)
Antoine
________________________________ Date: Wed, 20 Jul 2011 11:47:51 -0400 Subject: Re: [Haskell-beginners] Parse error: naked expression at top level From: allbery.b@gmail.com To: rwobben@hotmail.com CC: beginners@haskell.org
On Wed, Jul 20, 2011 at 11:30, Roelof Wobben
wrote: replicate :: Int -> a -> [a] replicate a xs = [xs | x' <= a <--xs]
replicate 3 True
That last line is fine at a GHCi prompt but not in a program. (Files loaded by ghci are not scripts! They are treated the same way as program files fed to ghc or runhaskell.) -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
 
            On Wed, 20 Jul 2011 15:50:13 +0000
Roelof Wobben 
Oke,
So In the file I have to load I must put the first 2 lines. And in the prompt I have to do the last line,
Or is there a way I can use all three lines in a file ?
Why not something like this? mytest = replicate 3 True Then you can load it. -- Manfred
 
            On 7/20/11, Roelof Wobben 
Hello,
I made this little script :
replicate :: Int -> a -> [a] replicate a xs = [xs | x' <= a <--xs]
I don't think this list comprehension works: - You've got the "<--" arrow instead of "<-". Maybe you're copy-pasting from Leksah, so it's causing the mistake in the copy-paste? - You haven't defined x' anywhere - I don't think you can combine a predicate (x' <= a) with a generator (a <- xs) - xs is your "feed" for the generator "a <- xs". What if, like in your example, xs is not a list? Also, for clarity, I would only name something "xs" if it is definitely a list. I don't want to spoon-feed you a solution, but I'd recommend: - Your "feed" in the generator (in your example the rightmost xs) being an infinite list, so that a is never a larger number than the number of elements in your "feed" - For clarity, don't define x', if you aren't going to use it. It's valid Haskell to write, for example: f :: [a] -> [Bool] f x = [True | _ <- x] Tom
participants (5)
- 
                 Antoine Latter Antoine Latter
- 
                 Brandon Allbery Brandon Allbery
- 
                 Manfred Lotz Manfred Lotz
- 
                 Roelof Wobben Roelof Wobben
- 
                 Tom Murphy Tom Murphy