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:  Does one need a ticket to attend ICFP? (Sebastien Zany)
   2.  GLfloat cast... have I got it right? (Sean Charles)
   3. Re:  GLfloat cast... have I got it right? (Felipe Almeida Lessa)
   4. Re:  GLfloat cast... have I got it right? (Arlen Cuss)
   5. Re:  GLfloat cast... have I got it right? (Daniel Fischer)
   6. Re:  GLfloat cast... have I got it right? (Arlen Cuss)
   7.  undefined symbol not allowed? (Christopher Howard)
   8. Re:  undefined symbol not allowed? (Antoine Latter)
   9. Re:  undefined symbol not allowed? (Brandon Allbery)


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

Message: 1
Date: Thu, 7 Jul 2011 08:10:06 -0700
From: Sebastien Zany <[email protected]>
Subject: Re: [Haskell-beginners] Does one need a ticket to attend
        ICFP?
To: [email protected]
Message-ID:
        <caa+2x_wbkzetbg1vbhfk2w6qekfjhdpoqg-jiaz9va_8qn2...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Oh good I was afraid it was closed :-)

Thanks!


On Wed, Jul 6, 2011 at 3:46 PM, Erik de Castro Lopo <[email protected]>wrote:

> Sebastien Zany wrote:
>
> > There's a "Registration" item on the left menu at
> > http://www.icfpconference.org/icfp2011/ but it doesn't link to anywhere.
> Can
> > I just show up?
>
> I don't thnk registration is open yet.
>
> Erik
> --
> ----------------------------------------------------------------------
> Erik de Castro Lopo
> http://www.mega-nerd.com/
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110707/05f025f1/attachment-0001.htm>

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

Message: 2
Date: Thu, 07 Jul 2011 17:19:35 +0100
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] GLfloat cast... have I got it right?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

As I chunder on through OpenGL-land with Haskell I find things that 
sometimes confuse me!
Is there some kind of assumption being made here about the remaining two 
zeros?

  color $ Color3 (0::GLfloat) 0 0

I can see that is is typing the first zero to GLfloat but why don't I 
need to do it to the remaining two zeros?

Color3 is "Color3 !a !a !a"

The !a is, IIUIC, a strictness instruction that ensures that whatever 
expression I put here is evaluated immediately i.e. no thunk is 
generated and presumably no space leaks either: something rendering at 
60 fps with 'interesting' calculations for RGB values for example could 
cripple the application!

But back to the syntax: I am guessing (and hoping I've got it right for 
the *right* reasons) that it works because the definition says "a" for 
all three and that explicitly typing the first one automatically tells 
(infers!) the type inference system that the other two are to be treated 
as GLfloat types too.

:)




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

Message: 3
Date: Thu, 7 Jul 2011 13:21:54 -0300
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] GLfloat cast... have I got it right?
To: Sean Charles <[email protected]>
Cc: [email protected]
Message-ID:
        <CANd=ogf6b0+xhh-4a0rewm9xrf_q55413okr-ibovqpa-me...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Thu, Jul 7, 2011 at 1:19 PM, Sean Charles <[email protected]> wrote:
> But back to the syntax: I am guessing (and hoping I've got it right for the
> *right* reasons) that it works because the definition says "a" for all three
> and that explicitly typing the first one automatically tells (infers!) the
> type inference system that the other two are to be treated as GLfloat types
> too.

Yes, that's right =).

Cheers,

-- 
Felipe.



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

Message: 4
Date: Fri, 08 Jul 2011 08:37:56 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] GLfloat cast... have I got it right?
To: Sean Charles <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

> The !a is, IIUIC, a strictness instruction that ensures that whatever
> expression I put here is evaluated immediately i.e. no thunk is
> generated and presumably no space leaks either: something rendering at
> 60 fps with 'interesting' calculations for RGB values for example could
> cripple the application!

Correct. (I believe it forces the expression to WHNF, which basically
means 'forces the value' in the case of things like numbers and floats,
AFAIK, but I've only just learned about that syntax myself)

> But back to the syntax: I am guessing (and hoping I've got it right for
> the *right* reasons) that it works because the definition says "a" for
> all three and that explicitly typing the first one automatically tells
> (infers!) the type inference system that the other two are to be treated
> as GLfloat types too.

Exactly. As you've specified one of them to be a given type (note that I
think it would be slightly off the mark to call it a "cast" here [as per
the subject], unless that terminology is the norm for numbers in Haskell
-- it reads more [to me] like you're actually informing the typing
engine that it *is* a GLfloat, not to make it into one!), the rest must
follow by virtue of them sharing that type.

Cheers,

A



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

Message: 5
Date: Fri, 8 Jul 2011 01:47:25 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] GLfloat cast... have I got it right?
To: [email protected]
Cc: Sean Charles <[email protected]>
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Friday 08 July 2011, 00:37:56, Arlen Cuss wrote:
> > The !a is, IIUIC, a strictness instruction that ensures that whatever
> > expression I put here is evaluated immediately i.e. no thunk is
> > generated and presumably no space leaks either: something rendering at
> > 60 fps with 'interesting' calculations for RGB values for example
> > could cripple the application!
> 
> Correct. (I believe it forces the expression to WHNF, which basically
> means 'forces the value' in the case of things like numbers and floats,
> AFAIK, but I've only just learned about that syntax myself)

Right. Precisely, it forces the fields to WHNF *when the entire value is 
forced to WHNF*.

With

data Foo a = F a a

(x :: Foo Int) `seq` ()

forces the constructor F but leaves the fields alone, so

(F undefined undefined) `seq` ()

evaluates to ().

With

data Bar a = B !a !a

(y :: Bar Int) `seq` ()

forces the constructor B and also the fields [to WHNF] (since the fields 
have type Int, that means full evaluation), so

(B 3 undefined) `seq` ()

yields _|_. But

(B (3:undefined) (4:undefined)) `seq` ()

evaluates to ().

So putting a `!' on a component of, say, type String only forces it enough 
to see whether it's empty or not. `!' is most useful for types where WHNF 
implies sufficient evaluation, which means the constructors of that type 
need to have strict fields too (if any). Types like Integer, Int, Word, 
Double, Float have (in GHC) strict fields in the form of "raw bytes", 
Data.Map has `!'-ed fields (but the values are lazy), so with

data Quux a b = Q ... !(Map a b) ...

forcing a value of such a type to WHNF also forces the entire spine of the 
Map, which often is sufficient, but not always. If you also need the values 
in the Map to be evaluated, you have to use other methods (normally it's 
best to make sure the values are evaluated when they are inserted into the 
Map, doing that later tends to be expensive).

> 
> > But back to the syntax: I am guessing (and hoping I've got it right
> > for the *right* reasons) that it works because the definition says
> > "a" for all three and that explicitly typing the first one
> > automatically tells (infers!) the type inference system that the
> > other two are to be treated as GLfloat types too.
> 
> Exactly. As you've specified one of them to be a given type (note that I
> think it would be slightly off the mark to call it a "cast" here [as per
> the subject], unless that terminology is the norm for numbers in Haskell

It's not. The term "cast" is rarely used in Haskell. For (0 :: Float) one 
would rather say that one specifies the type.
But calling it a cast isn't wrong, since it means "apply this conversion 
function to that value", what a cast in other languages means too.
However, there's a difference.
In C (Java, C#, ...), if I have

int x, y;
// stuff setting the values

I can do

double d = (double)x / y;

so I can tell the compiler explicitly to convert the one monomorphic value 
to another type and the compiler automatically converts the other to the 
same type to perform the calculation.

In Haskell, a) I cannot invoke a conversion function on a monomorphic value 
by just giving a type signature, b) I have to explicitly convert all 
involved values.

Re a): Number literals come with an implicit conversion function,
1234 and 5.678 stand for "fromInteger 1234" resp. "fromRational 5.678"
and a type signature tells the compiler which fromInteger/fromRational to 
invoke. Number literals are polymorphic expressions and polymorphic 
expressions can be "cast" to a specific type by a type signature [which 
tells the compiler which fromInteger, return, ... to use]. To convert a 
monomorphic expression, however, the conversion function has to be 
explicitly invoked.

> -- it reads more [to me] like you're actually informing the typing
> engine that it *is* a GLfloat, not to make it into one!), the rest must
> follow by virtue of them sharing that type.

Yup. Per the data definition, they all have the same type, so when you know 
one, you know them all.




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

Message: 6
Date: Fri, 08 Jul 2011 10:04:16 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] GLfloat cast... have I got it right?
To: Daniel Fischer <[email protected]>
Cc: Sean Charles <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

> Right. Precisely, it forces the fields to WHNF *when the entire value is 
> forced to WHNF*.

A-ha! That gives a good definition for me to work from.

Thanks for the seq examples; I'm only just starting to get to the point
where (I think) I can consider these issues with any insight.

> So putting a `!' on a component of, say, type String only forces it enough 
> to see whether it's empty or not. `!' is most useful for types where WHNF 
> implies sufficient evaluation, which means the constructors of that type 
> need to have strict fields too (if any). Types like Integer, Int, Word, 
> Double, Float have (in GHC) strict fields in the form of "raw bytes", 
> Data.Map has `!'-ed fields (but the values are lazy), so with
> 
> data Quux a b = Q ... !(Map a b) ...
> 
> forcing a value of such a type to WHNF also forces the entire spine of the 
> Map, which often is sufficient, but not always. If you also need the values 
> in the Map to be evaluated, you have to use other methods (normally it's 
> best to make sure the values are evaluated when they are inserted into the 
> Map, doing that later tends to be expensive).

That makes a lot of sense.

> Re a): Number literals come with an implicit conversion function,
> 1234 and 5.678 stand for "fromInteger 1234" resp. "fromRational 5.678"
> and a type signature tells the compiler which fromInteger/fromRational to 
> invoke. Number literals are polymorphic expressions and polymorphic 
> expressions can be "cast" to a specific type by a type signature [which 
> tells the compiler which fromInteger, return, ... to use]. To convert a 
> monomorphic expression, however, the conversion function has to be 
> explicitly invoked.

Polymorphic expressions are handy :-)

One of the things that surprised me the most - particularly coming to
Haskell by way of ML - was terms like `minBound', `maxBound', `read x'
and so on.

Seeing how any term could be defined per-instance in a typeclass -- not
just functions --  was a key moment, as it's easy to get stuck (very
hard) in a given mindset. From ML, polymorphic functions made sense, but
*plain values*?

(Or not so plain.)

Of course, where typeclasses are concerned, there's not much difference,
but I didn't even consider that at first.

A



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

Message: 7
Date: Thu, 07 Jul 2011 20:42:40 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] undefined symbol not allowed?
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

I'm one of those evil people who loves to sprinkle Unicode throughout my 
code. I thought it was pretty cool when I learned about the 
UnicodeSyntax language extension, as well as the base-unicode-symbols 
package. However, I am a little perplexed that this symbol is not 
provided by either of those:

?

That is, the "bottom" symbol, Unicode #22A5 (\8869), which I have seen 
in some programming texts as representing the undefined expression.

I tried just defining

? = undefined

But ghc won't parse that. Why is this? And is there a way to make it work?

-- 
frigidcode.com
theologia.indicium.us



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

Message: 8
Date: Thu, 7 Jul 2011 23:52:23 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] undefined symbol not allowed?
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <cakjsnqhojjmrmkoerksh1crozo_upzubnkhwczuvazrmwzq...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Thu, Jul 7, 2011 at 11:42 PM, Christopher Howard
<[email protected]> wrote:
> I'm one of those evil people who loves to sprinkle Unicode throughout my
> code. I thought it was pretty cool when I learned about the UnicodeSyntax
> language extension, as well as the base-unicode-symbols package. However, I
> am a little perplexed that this symbol is not provided by either of those:
>
> ?
>
> That is, the "bottom" symbol, Unicode #22A5 (\8869), which I have seen in
> some programming texts as representing the undefined expression.
>
> I tried just defining
>
> ? = undefined
>
> But ghc won't parse that. Why is this? And is there a way to make it work?
>

What error message do you get?

> --
> frigidcode.com
> theologia.indicium.us
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

Message: 9
Date: Fri, 8 Jul 2011 00:54:23 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] undefined symbol not allowed?
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <cakfcl4xqtknnzewkxbojaxrt+dgco4dem1kzwxad5tydgd1...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

On Fri, Jul 8, 2011 at 00:42, Christopher Howard
<[email protected]> wrote:
> I tried just defining
>
> ? = undefined
>
> But ghc won't parse that. Why is this? And is there a way to make it work?

The language spec divides characters up as being identifier characters
vs. punctuation, using the rules for Unicode; ? is the latter.  As
such, it can only appear infix or within parentheses, the latter being
the syntax to use an operator as a function; compare (+) and note that
it's the trivial case of section syntax).  So if you're willing to
settle for using it as "(?)" everywhere (*including* when defining it)
then you can do it, but bare "?" isn't legal.

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


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

Reply via email to