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.  OpenGL keyboardMouseCallback ...confused over    type (Sean Charles)
   2. Re:  OpenGL keyboardMouseCallback ...confused over type
      (Arlen Cuss)
   3.  Problem building MusicXML (Dennis Raddle)
   4.  Could not find file in module graph (?ystein Kolsrud)
   5. Re:  Problem building MusicXML (Stephen Tetley)
   6. Re:  OpenGL keyboardMouseCallback ...confused over type
      (Sean Charles)


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

Message: 1
Date: Thu, 30 Jun 2011 23:34:05 +0100
From: Sean Charles <[email protected]>
Subject: [Haskell-beginners] OpenGL keyboardMouseCallback ...confused
        over    type
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

I asked a question the other day about passing application state around 
an OpenGL program and I've consulted RWH and the inter-web extensively 
and I think I am on the right lines so far!

In my main program, I use Data.IORef like this:

     gameState <- newIORef $ newGameState

and GameState contains all the stuff to do with the game model. Next the 
confusing bit... to make myself learn things I typed out the full type 
of the keyboardMouseCallback function:

     myKeyMouse :: Key -> KeyState -> Modifiers -> Position -> IO ()

and slotted it into the code like so:

     keyboardMouseCallback $= Just myKeyMouse

In order to be able to pass the "IORef GameState" into the keyboard 
handler I have to re-type my keyboardMouseCallback function like so:

     myKeyMouse :: IORef GameState -> Key -> KeyState -> Modifiers -> 
Position -> IO ()

and modify the assignment in main to this:

     keyboardMouseCallback $= Just (myKeyMouse gameState)

But I haven't really understood *why* that is the case. The 
displayCallback is also similarly affected as it is now:

     myDisplay :: IORef GameState -> IO ()
     ... displayCallback $= (myDisplay gameState)

and again I am not sure what magic is happening here to have made it 
compile and work! My real source of confusion is over my apparent 
victory over the type system in that I appear to have extended the type 
signature (is that the correct term?) for both of the callbacks be 
prepending "IORef GameState" to them and yet it all compiles and works. 
Is "prepending" the key ? I feel a tingling of Eureka! organ but I am 
not sure yet.

Explanations are welcome as I am sure there is something "important" 
here that will really advance my understanding of the type system. It 
smells like curry but I don't think... hang on... the keyboard one is 
wrapped in the Maybe monad... therefore(?) the function I am handing in 
can be *any* type so long as they actually match types! Is that it then? 
I can smell partial application and curry now.
HELP!
Thanks,
Sean.

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

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

Message: 2
Date: Fri, 01 Jul 2011 08:53:47 +1000
From: Arlen Cuss <[email protected]>
Subject: Re: [Haskell-beginners] OpenGL keyboardMouseCallback
        ...confused over type
To: Sean Charles <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

> confusing bit... to make myself learn things I typed out the full type
> of the keyboardMouseCallback function:

(you'll actually do this in production code too! It's a good habit.)

>     myKeyMouse :: Key -> KeyState -> Modifiers -> Position -> IO ()
> 
> and slotted it into the code like so:
> 
>     keyboardMouseCallback $= Just myKeyMouse

Okay -- so here we're seeing that keyboardMouseCallback itself is an IORef:

> keyboardMouseCallback :: IORef (Maybe (Key -> KeyState -> Modifiers ->
Position -> IO ()))

Keep in mind also:

> ($=) :: IORef a -> a -> IO ()

> In order to be able to pass the "IORef GameState" into the keyboard
> handler I have to re-type my keyboardMouseCallback function like so:
> 
>     myKeyMouse :: IORef GameState -> Key -> KeyState -> Modifiers ->
> Position -> IO ()
> 
> and modify the assignment in main to this:
> 
>     keyboardMouseCallback $= Just (myKeyMouse gameState)

Now let's look at the reason it works.

Your types are:

> keyboardMouseCallback :: IORef (Maybe (Key -> KeyState -> Modifiers ->
Position -> IO ()))
> myKeyMouse :: IORef GameState -> Key -> KeyState -> Modifiers ->
Position -> IO ()

Now, what's the type of the expression `myKeyMouse gameState'? Well,
you've assigned the first argument -- all functions are curried -- so
you get a partial application:

> myKeyMouse gameState :: Key -> KeyState -> Modifiers -> Position -> IO ()

Now you wrap that in Just:

> Just (myKeyMouse gameState) :: Maybe (Key -> KeyState -> Modifiers ->
Position -> IO ())

What was the type of keyboardMouseCallback again?

> keyboardMouseCallback :: IORef (Maybe (Key -> KeyState -> Modifiers ->
Position -> IO ()))

So the partial application returns a function with the first argument
fixed -- and the resulting function's type is that which is used for the
callbacks.

HTH a little.

A



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

Message: 3
Date: Thu, 30 Jun 2011 20:57:25 -0700
From: Dennis Raddle <[email protected]>
Subject: [Haskell-beginners] Problem building MusicXML
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

My problem is that "cabal install" just hangs at the line "Building
HaXml-1.22..." and I don't know how to figure out what it's trying to do.

Background:

My main goal is to use the 'musicxml' package. On Windows XP, I installed
Haskell Package 2010.1.0.0. (I needed base 3 for compatibility with
musicxml.) I did 'cabal install musicxml'. First I got warning:

Warning: c:\Documents and Settings\Mike\Application Data\cabal\config:
Unrecognized field world-file on line 15

Then it built text-0.11.1.3, polyparse-1.7, then it started to build
HaXml-1.22 and got as far as printing "Building HaXml-1.22..." but hung. No
CPU was being consumed.

Dennis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110630/c5afd385/attachment-0001.htm>

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

Message: 4
Date: Fri, 1 Jul 2011 07:30:49 +0200
From: ?ystein Kolsrud <[email protected]>
Subject: [Haskell-beginners] Could not find file in module graph
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi! I'm using version 2.0.4 of Eclipse FP and I very often get an
error saying "Could not find file in module graph.". I did a quick
search on the web for this message, but all I could find was some old
threads discussing an issue with this symptom (for instance
http://code.google.com/p/scion-lib/issues/detail?id=36#c1). Does
anyone know what the error means and how I can avoid it?

-- 
Mvh ?ystein Kolsrud



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

Message: 5
Date: Fri, 1 Jul 2011 07:34:50 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Problem building MusicXML
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

The last good version of HaXml seems to be 1.20.2 - according to
Hackage version 1.22 doesn't build due to missing file errors. So I
would install this version by itself, then when you try to install to
install musicxml once you have a working HaXml.

I don't use cabal-install so unfortunately I can't tell you which
commands to use, but I know you can tell it to install particaular
versions rather than "latest".

On 1 July 2011 04:57, Dennis Raddle <[email protected]> wrote:
> My problem is that "cabal install" just hangs at the line "Building
> HaXml-1.22..." and I don't know how to figure out what it's trying to do.
>



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

Message: 6
Date: Fri, 01 Jul 2011 08:04:31 +0100
From: Sean Charles <[email protected]>
Subject: Re: [Haskell-beginners] OpenGL keyboardMouseCallback
        ...confused over type
To: Arlen Cuss <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

Arlen,

thanks for that... I think it confirms that my head was on "the right 
track" but it was pitch-black in there and I had my eyes closed. It 
saddens me that the answer to one of my questions is harder to 
understand than the question was to write in the first place, LMAO, I 
love Haskell for this... it's making me think about stuff more and more 
and I like it. I am determined that Haskell is the end of the line until 
son of Haskell comes out! LOL.

Would you mind clarifying a point for me regarding partial application, 
currying and types as I am now a bit confused... I've written enough 
point free stuff to understand both partial application and currying so 
that's fine... what's confusing me is in your reply you say:

   "So the partial application returns a function with the first argument
   fixed -- and the resulting function's type is that which is used for the
   callbacks. "

Am I correct in thinking then that data types are constructors, *are* 
_just functions too_, I think that's correct and if so I will re-read 
RWH in certain places to see how it wasn't clear enough to me...

On page 42(!) of Real World Haskell it says: "We can create a new value 
of type BookInfo by treating Book as a function and applying it with 
arguments of types Int, String, and [String]".

On page 41 we have this definition:
   data BookInfo = Book Int String [String] deriving (Show)

So, is "Book" a function or is it not a function, as implied by the 
statement "by treating Book _as_ a function" ? That would help me 
greatly, to know if data constructors are just functions or something 
"special" (constructors of data types) but for all intents and purposes 
they smell, act, look and behave as functions. Singing: "La dee da La 
dee dee, Eric the half-a-boook...."

I created a file containing that definition and loaded it into ghci:

*Main> :type Book
Book :: Int -> String -> [String] -> BookInfo

This looks like a function to me! LOL, so I added another constructor 
like so:

data BookInfo = Book Int String [String]
                 | Paperback Int String [String]
                 deriving(Show)

...and was beheld unto me...

*Main> :type Paperback
Paperback :: Int -> String -> [String] -> BookInfo

Hmmm... another function returning the same -*-. So is the sentence a 
bit misleading to say "as a function" when it means, at least as far as 
I can see "because Book _is_ a function" ?

I think I am understanding things a little better now but some expert 
clarification would help!




Is this line of reasoning correct:

   o Haskell is functional therefore...
   o *everything* is a function
   o functions are automatically curried where required (to get partials)...
   o data constructors *are* functions (as opposed to being a separate
      thing like structs in C for example)...
   o data constructors can be partially applied (Eureka![?])


Man, I think your answer is more understandable just from typing the 
above questions, surely the sign of a great answer to a question.

Thanks!
Sean.

On 30/06/11 23:53, Arlen Cuss wrote:
>> confusing bit... to make myself learn things I typed out the full type
>> of the keyboardMouseCallback function:
> (you'll actually do this in production code too! It's a good habit.)
>
>>      myKeyMouse :: Key ->  KeyState ->  Modifiers ->  Position ->  IO ()
>>
>> and slotted it into the code like so:
>>
>>      keyboardMouseCallback $= Just myKeyMouse
> Okay -- so here we're seeing that keyboardMouseCallback itself is an IORef:
>
>> keyboardMouseCallback :: IORef (Maybe (Key ->  KeyState ->  Modifiers ->
> Position ->  IO ()))
>
> Keep in mind also:
>
>> ($=) :: IORef a ->  a ->  IO ()
>> In order to be able to pass the "IORef GameState" into the keyboard
>> handler I have to re-type my keyboardMouseCallback function like so:
>>
>>      myKeyMouse :: IORef GameState ->  Key ->  KeyState ->  Modifiers ->
>> Position ->  IO ()
>>
>> and modify the assignment in main to this:
>>
>>      keyboardMouseCallback $= Just (myKeyMouse gameState)
> Now let's look at the reason it works.
>
> Your types are:
>
>> keyboardMouseCallback :: IORef (Maybe (Key ->  KeyState ->  Modifiers ->
> Position ->  IO ()))
>> myKeyMouse :: IORef GameState ->  Key ->  KeyState ->  Modifiers ->
> Position ->  IO ()
>
> Now, what's the type of the expression `myKeyMouse gameState'? Well,
> you've assigned the first argument -- all functions are curried -- so
> you get a partial application:
>
>> myKeyMouse gameState :: Key ->  KeyState ->  Modifiers ->  Position ->  IO ()
> Now you wrap that in Just:
>
>> Just (myKeyMouse gameState) :: Maybe (Key ->  KeyState ->  Modifiers ->
> Position ->  IO ())
>
> What was the type of keyboardMouseCallback again?
>
>> keyboardMouseCallback :: IORef (Maybe (Key ->  KeyState ->  Modifiers ->
> Position ->  IO ()))
>
> So the partial application returns a function with the first argument
> fixed -- and the resulting function's type is that which is used for the
> callbacks.
>
> HTH a little.
>
> A

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110701/65ab83fd/attachment.htm>

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

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


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

Reply via email to