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:  Parse error: naked expression at top level (Brandon Allbery)
   2. Re:  Drawing Information from a function already  defined
      (Felipe Almeida Lessa)
   3. Re:  Parse error: naked expression at top level (Roelof Wobben)
   4. Re:  Drawing Information from a function already  defined
      (aditya siram)
   5.  loop problem (Roelof Wobben)
   6. Re:  Parse error: naked expression at top level (Antoine Latter)
   7. Re:  Parse error: naked expression at top level (Manfred Lotz)
   8. Re:  Parse error: naked expression at top level (Tom Murphy)
   9. Re:  loop problem (Tom Murphy)


----------------------------------------------------------------------

Message: 1
Date: Wed, 20 Jul 2011 11:47:51 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Parse error: naked expression at top
        level
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID:
        <CAKFCL4UWQoCzKab-4Y0W75YD9K0jqL1EgTnHdanKF3=9oge...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Wed, Jul 20, 2011 at 11:30, Roelof Wobben <[email protected]> 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                                      [email protected]
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110720/86a1a2cc/attachment-0001.htm>

------------------------------

Message: 2
Date: Wed, 20 Jul 2011 12:48:18 -0300
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Drawing Information from a function
        already defined
To: Clockwork PC <[email protected]>
Cc: [email protected]
Message-ID:
        <CANd=OGE4icvzsyvBUn-aXOHkBKi9JGSCWrZ5O3=gnfavbyl...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Wed, Jul 20, 2011 at 10:45 AM, Clockwork PC <[email protected]> wrote:
> Defined my function:
>
> Prelude> let rightTriangles = [ (a,b,c) | c <- [1..10], b <- [1..10], a <-
> [1..10], a^2 + b^2 == c^2 ]

Minor correction: rightTriangles is not a function, it is a value.
Note that it takes no arguments.

Cheers, =)

-- 
Felipe.



------------------------------

Message: 3
Date: Wed, 20 Jul 2011 15:50:13 +0000
From: Roelof Wobben <[email protected]>
Subject: Re: [Haskell-beginners] Parse error: naked expression at top
        level
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"


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: [email protected]
To: [email protected]
CC: [email protected]

On Wed, Jul 20, 2011 at 11:30, Roelof Wobben <[email protected]> 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                                      [email protected]
wandering unix systems administrator (available)     (412) 475-9364 vm/sms



                                          
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110720/2cc34ccb/attachment-0001.htm>

------------------------------

Message: 4
Date: Wed, 20 Jul 2011 11:20:26 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Drawing Information from a function
        already defined
To: Clockwork PC <[email protected]>
Cc: [email protected]
Message-ID:
        <cajrreyhnfnn-xxjpr3rn8obhuewcmjd-bfhhiq4uqnpyhsf...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi,
For adding constraints I think that using List as a monad is the most
flexible way to go. The first two functions below show the monadic
equivalent of your first two list comprehension examples. The third
shows how to add constraints without having to rewrite the function.
The first two function could have been expressed using only the third
but are presented to show how it was built.

-deech

  import Control.Monad

  -- triples' == [(a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10]]
  triples' = do
    a <- [1 .. 10]
    b <- [1 .. 10]
    c <- [1 .. 10]
    return (a,b,c)

  -- triples'' (\(a,b,c) -> a + b + c == 24) ==
  -- [(a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10], a + b + c == 24]
  triples'' constraint = do
    a <- [1 .. 10]
    b <- [1 .. 10]
    c <- [1 .. 10]
    guard $ constraint (a,b,c)
    return (a,b,c)

  -- triples''' [\(a,b,c) -> a^2 + b^2 == c^2, \(a,b,c) -> a + b + c == 24] ==
  -- [(a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10], a^2 + b^2 =
c^2, a + b + c == 24]
  triples''' :: [(Int,Int,Int) -> Bool] -> [(Int,Int,Int)]
  triples''' constraints = do
    a <- [1 .. 10]
    b <- [1 .. 10]
    c <- [1 .. 10]
    sequence_ $ map (\constraint -> guard $ constraint (a,b,c)) constraints
    return (a,b,c)

On Wed, Jul 20, 2011 at 8:45 AM, Clockwork PC <[email protected]> wrote:
> Greetings Haskell community,
>
> This is my first ever post so please be gentle...
>
> Here's where I got to:
>
> Jumped into GHCi:
>
> GHCi, version 7.0.3: http://www.haskell.org/ghc/? :? for help
> Loading package ghc-prim ... linking ... done.
> Loading package integer-gmp ... linking ... done.
> Loading package base ... linking ... done.
>
> Defined my function:
>
> Prelude> let rightTriangles = [ (a,b,c) | c <- [1..10], b <- [1..10], a <-
> [1..10], a^2 + b^2 == c^2 ]
>
> Tested my function:
>
> Prelude> rightTriangles
> [(4,3,5),(3,4,5),(8,6,10),(6,8,10)]
>
> Now, I want to define a refinement of this that will only select values
> whose total is 24.
>
> I could write it so:
>
> let rightTriangles = [ (a,b,c) | c <- [1..10], b <- [1..10], a <- [1..10],
> a^2 + b^2 == c^2, a+b+c == 24]
>
> However, it seems like a bit of a waste if I already have "rightTriangles"
> defined.
>
> I tried a few things, but none of them worked:
>
> Prelude> let rightTriangles` = rightTriangles, a+b+c == 24
>
> <interactive>:1:21: parse error on input `='
> Prelude> let rightTriangles` = rightTriangles | a+b+c == 24
>
> <interactive>:1:21: parse error on input `='
> Prelude> let rightTriangles` = [rightTriangles, a+b+c == 24]
>
> <interactive>:1:21: parse error on input `='
> Prelude> let rightTriangles` = [rightTriangles | a+b+c == 24]
>
> <interactive>:1:21: parse error on input `='
>
> Basically, I'm trying to work out how to draw data from a list already to
> hand.
>
> Alexander
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>



------------------------------

Message: 5
Date: Wed, 20 Jul 2011 16:29:57 +0000
From: Roelof Wobben <[email protected]>
Subject: [Haskell-beginners] loop problem
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"


Hello, 

I need to make a sort of loop so a text is displayed several times.

So this idea :

repeat 3 true will be True True True.

So in another language I would have programmed.


for teller = 1 to a 
    print text 

But I need to use list comprehession.

So I thougt I use this :

replicate :: Int -> a -> [a]
replicate a xs = [xs | x' <= a <-xs]

But now I get this message :

oefening.hs:2:24: Parse error in pattern: x' <= a


Where did I go wrong here ?

Roelof

                                          
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110720/70aa6ef6/attachment-0001.htm>

------------------------------

Message: 6
Date: Wed, 20 Jul 2011 11:42:41 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Parse error: naked expression at top
        level
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID:
        <cakjsnqgcl7xpwnc-7vrhqm_thz0kwhd-hcge8gywccmowt6...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Wed, Jul 20, 2011 at 10:50 AM, Roelof Wobben <[email protected]> wrote:
> 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: [email protected]
> To: [email protected]
> CC: [email protected]
>
> On Wed, Jul 20, 2011 at 11:30, Roelof Wobben <[email protected]> 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 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [email protected]
> wandering unix systems administrator (available) ? ? (412) 475-9364 vm/sms
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>



------------------------------

Message: 7
Date: Wed, 20 Jul 2011 18:52:20 +0200
From: Manfred Lotz <[email protected]>
Subject: Re: [Haskell-beginners] Parse error: naked expression at top
        level
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII

On Wed, 20 Jul 2011 15:50:13 +0000
Roelof Wobben <[email protected]> wrote:

> 
> 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





------------------------------

Message: 8
Date: Wed, 20 Jul 2011 14:17:01 -0400
From: Tom Murphy <[email protected]>
Subject: Re: [Haskell-beginners] Parse error: naked expression at top
        level
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID:
        <cao9q0tuqpenkcswnlawr-aqm1nozcofxse5rsrgvyltnouu...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On 7/20/11, Roelof Wobben <[email protected]> wrote:
>
> 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



------------------------------

Message: 9
Date: Wed, 20 Jul 2011 14:25:27 -0400
From: Tom Murphy <[email protected]>
Subject: Re: [Haskell-beginners] loop problem
To: Roelof Wobben <[email protected]>
Cc: [email protected]
Message-ID:
        <cao9q0tvf1uz9iemyhf7q7ahlqs8pkokdivyd3xezagh3vus...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi Roelof,
     For small questions like this, you might want to try the Haskell
IRC channel (http://www.haskell.org/haskellwiki/IRC_channel).

Tom

On 7/20/11, Roelof Wobben <[email protected]> wrote:
>
> Hello,
>
> I need to make a sort of loop so a text is displayed several times.
>
> So this idea :
>
> repeat 3 true will be True True True.
>
> So in another language I would have programmed.
>
>
> for teller = 1 to a
>     print text
>
> But I need to use list comprehession.
>
> So I thougt I use this :
>
> replicate :: Int -> a -> [a]
> replicate a xs = [xs | x' <= a <-xs]
>
> But now I get this message :
>
> oefening.hs:2:24: Parse error in pattern: x' <= a
>
>
> Where did I go wrong here ?
>
> Roelof
>
>



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 37, Issue 39
*****************************************

Reply via email to