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:  Unit numeric type pattern (Stephen Tetley)
   2. Re:  Unit numeric type pattern (Andres Loeh)
   3.  boomBangs xs = [ if x < 10 then "BOOM!" else "BANG!" | x <-
      xs, odd x] (anthony niro)
   4. Re:  boomBangs xs = [ if x < 10 then "BOOM!"      else "BANG!" | x
      <- xs, odd x] (Daniel Fischer)
   5. Re:  boomBangs xs = [ if x < 10 then "BOOM!" else "BANG!" | x
      <- xs, odd x] (Tom Murphy)
   6.  not getting heap profiling data from test runs (Sean Perry)
   7.  How to compile stub? (Zhi-Qiang Lei)


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

Message: 1
Date: Tue, 21 Jun 2011 15:37:58 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Unit numeric type pattern
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I'd read it as the valid units are numeric types like "Int" or
"Rational" ("unit" here being synonymous with "type").

GHC's error messages are not always intuitive. I think the GHC
developers had a sweep through some of them a year or two ago trying
to find more self-explanatory messages.



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

Message: 2
Date: Tue, 21 Jun 2011 18:38:09 +0200
From: Andres Loeh <[email protected]>
Subject: Re: [Haskell-beginners] Unit numeric type pattern
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi.

On Tue, Jun 21, 2011 at 10:38 AM, Christopher Howard
<[email protected]> wrote:
> What is a "unit numeric type pattern", as in the error: "Only unit
> numeric type pattern is valid". I can cause this error by mixing numbers
> into type definitions. And, therefore, I know how to avoid this error.
> But the error indicates that there /is/ such a thing as "valid" "unit
> numeric type pattern", and consequently I am quite curious as to what a
> such a thing is and what it would look like in code.

It's a hack (and I believe one that can soon be deprecated). It allows
the number "1" to be used as a type, which is then interpreted as
being isomorphic to GHC.Generics.Unit. Any other number in a type will
produce the strange error you just mentioned. So this is syntactic
sugar that has been added to support a particular language extension
for generic deriving. I think the new generic deriving mechanism
currently being implemented by Pedro doesn't rely/benefit from nicer
syntax for the unit type. So this could be removed soon, and free up
the syntax for something like type-level naturals.

Cheers,
  Andres



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

Message: 3
Date: Tue, 21 Jun 2011 19:58:05 +0000
From: anthony niro <[email protected]>
Subject: [Haskell-beginners] boomBangs xs = [ if x < 10 then "BOOM!"
        else "BANG!" | x <- xs, odd x]
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"


Hello,

My name is Anthony i have few question about Haskell.

I was reading a tutorial everything goes well. but now i have few things that i 
dont understang.

HERE:

boomBangs xs = [ if x < 10 then "BOOM!" else "BANG!" | x <- xs, odd x]



I dont understand this line except the "if" "then" "else".  
What is xs? 
what is the |  ? 
 and why doing this  "  | x <- xs, odd x]"

why x <- xs????? what is that 

and what is odd x? 

thx everyone for answer me. 
                                          
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110621/a24fac3f/attachment-0001.htm>

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

Message: 4
Date: Tue, 21 Jun 2011 22:24:55 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] boomBangs xs = [ if x < 10 then
        "BOOM!" else "BANG!" | x <- xs, odd x]
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="utf-8"

On Tuesday 21 June 2011, 21:58:05, anthony niro wrote:
> Hello,
> 
> My name is Anthony i have few question about Haskell.
> 
> I was reading a tutorial everything goes well. but now i have few things
> that i dont understang.
> 
> HERE:
> 
> boomBangs xs = [ if x < 10 then "BOOM!" else "BANG!" | x <- xs, odd x]

That's a "list comprehension", if you want further information, searching 
for that term should turn up a few sources.

> 
> I dont understand this line except the "if" "then" "else".
> What is xs?

xs is the argument of the function boomBangs, it is a list.
(mnemonic: xs is the plural of x, it's common to denote single elements of 
a list by x, y, k, n, ... and the corresponding lists of [potentially] 
several such elements xs, ys, ...)

> what is the |  ?

It's a separator. It separates the elements of the result list from the 
generators and predicates.
List comprehension syntax is similar to set comprehension syntax, the above 
reads as

(if x < 10 then "BOOM!" else "BANG!") where x runs through/is drawn from xs 
and x is odd.

>  and why doing this  "  | x <- xs, odd x]"
> 
> why x <- xs????? what is that

"x <- xs" is the 'generator', you could also read that as "for all x in xs"
(but, as you will soon discover, it's more general, that works also for 
other things than lists).

> 
> and what is odd x?

That's a predicate or test, `odd' is a function which tests whether a 
number is odd, hence `odd x' tells you whether x is an odd number.
Appearing in that position, it acts as a filter, the expression to the left 
of the separator (`|', to reiterate) is only included in the result list if 
the test evaluates to True.

HTH,
Daniel




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

Message: 5
Date: Tue, 21 Jun 2011 16:26:56 -0400
From: Tom Murphy <[email protected]>
Subject: Re: [Haskell-beginners] boomBangs xs = [ if x < 10 then
        "BOOM!" else "BANG!" | x <- xs, odd x]
To: anthony niro <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi Anthony,
     What you're looking at is called a list comprehension. It's a way
of describing a list, to be created.

     It looks like you're doing the LYAH tutorial. It will explain
list comprehensions in general, but here's a start:

- xs is the list that your new list "comes from." boomBang is a
function. You give it a list (xs), and it will give you a new list
back.
- "x <- xs" is the way of saying that each element (called x) of your
new list comes form xs.
- the "|" separates the "sides" of the list comprehension. The left
side (the if statement) describes what each element of the new list
is.
- "  | x <- xs, odd x]" is doing two things: getting individual
elements from xs, and making sure that each element is odd. If "odd x"
(for some x) doesn't equal True, then that x never "makes it" to the
left hand side (the if statement)

Good luck with your studies!
Tom

On 6/21/11, anthony niro <[email protected]> wrote:
>
> Hello,
>
> My name is Anthony i have few question about Haskell.
>
> I was reading a tutorial everything goes well. but now i have few things
> that i dont understang.
>
> HERE:
>
> boomBangs xs = [ if x < 10 then "BOOM!" else "BANG!" | x <- xs, odd x]
>
>
>
> I dont understand this line except the "if" "then" "else".
> What is xs?
> what is the |  ?
>  and why doing this  "  | x <- xs, odd x]"
>
> why x <- xs????? what is that
>
> and what is odd x?
>
> thx everyone for answer me.
>



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

Message: 6
Date: Wed, 22 Jun 2011 01:05:14 -0700
From: Sean Perry <[email protected]>
Subject: [Haskell-beginners] not getting heap profiling data from test
        runs
To: Haskell Beginer <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

I have done the following:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.3
$ ghc -O2 -o myapp --make main.hs -prof -auto-all -rtsopts -fforce-recomp
$ ./myapp foo.csv +RTS -hb
$ cat ./myapp.hp
JOB "myapp foo.csv +RTS -hb"
DATE "Wed Jun 22 00:34 2011"
SAMPLE_UNIT "seconds"
VALUE_UNIT "bytes"
BEGIN_SAMPLE 0.00
END_SAMPLE 0.00
BEGIN_SAMPLE 0.00
END_SAMPLE 0.00

I get the same result from other -h options.

There are a total of 4 hs files compiled for this app. I see the same thing 
with my rpn calculator. Leaving off the -O2 does not help. Nor does 
-rtsopts=all.

What am I missing?

This is on OSX using the Haskel platform with a cabal installed Text.CSV (which 
I did --reinstall -p on to be certain).


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

Message: 7
Date: Wed, 22 Jun 2011 16:54:12 +0800
From: Zhi-Qiang Lei <[email protected]>
Subject: [Haskell-beginners] How to compile stub?
To: Haskell Beginer <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hi,

My attempt which compiles some files with stub failed. Can you tell me how to 
compile them? Thanks.

PrettyJSON.hs:

renderJValue :: JValue -> Doc
renderJValue (JBool True)  = text "true"
renderJValue (JBool False) = text "false"
renderJValue JNull         = text "null"
renderJValue (JNumber num) = double num
renderJValue (JString str) = string str

PrettyStub.hs:

import SimpleJSON

data Doc = ToBeDefined
         deriving (Show)

string :: String -> Doc
string str = undefined

text :: String -> Doc
text str = undefined

double :: Double -> Doc
double num = undefined


Result:

bogon% ghc -c PrettyJSON.hs PrettyStub.hs SimpleJSON.o
Warning: the following files would be used as linker inputs, but linking is not 
being done: SimpleJSON.o

PrettyJSON.hs:1:16:
    Not in scope: type constructor or class `JValue'

PrettyJSON.hs:1:26: Not in scope: type constructor or class `Doc'

PrettyJSON.hs:2:14: Not in scope: data constructor `JBool'

PrettyJSON.hs:2:29: Not in scope: `text'

PrettyJSON.hs:3:14: Not in scope: data constructor `JBool'

PrettyJSON.hs:3:29: Not in scope: `text'

PrettyJSON.hs:4:13: Not in scope: data constructor `JNull'

PrettyJSON.hs:4:29: Not in scope: `text'

PrettyJSON.hs:5:14: Not in scope: data constructor `JNumber'

PrettyJSON.hs:5:29: Not in scope: `double'

PrettyJSON.hs:6:14: Not in scope: data constructor `JString'

PrettyJSON.hs:6:29: Not in scope: `string'

Best regards,
Zhi-Qiang Lei
[email protected]




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

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


End of Beginners Digest, Vol 36, Issue 52
*****************************************

Reply via email to