qtHaskell, ForeignPtr

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

qtHaskell, ForeignPtr

Michael Mossey
I'm trying to learn qtHaskell, an interface to the Qt GUI library. I am
fairly new to Haskell, but have used Qt for a long time, so I thought I
could probably reasonably attempt to grok qtHaskell at this point.

My main question is: anyone recommended a good explanation of the foreign
function or foreign pointer interface?

My immediate question is that I was poking through the Qtc docs, and saw
this:


Documentation

   data Object a

Constructors

   QObject !(ForeignPtr a)

I am not sure how Haddock works. Is this telling me that an Object
constructor takes one argument, which is of type QObject, where QObject is
a type constructor that takes !(ForeignPtr a)? Or is this saying it takes
two arguments, a QObject and a !(ForeignPtr a). That latter makes more
sense I guess. What does the ! mean?

Thanks,
Mike

Reply | Threaded
Open this post in threaded view
|

qtHaskell, ForeignPtr

Daniel Fischer-4
Am Montag 07 September 2009 23:54:17 schrieb Michael Mossey:

> I'm trying to learn qtHaskell, an interface to the Qt GUI library. I am
> fairly new to Haskell, but have used Qt for a long time, so I thought I
> could probably reasonably attempt to grok qtHaskell at this point.
>
> My main question is: anyone recommended a good explanation of the foreign
> function or foreign pointer interface?
>
> My immediate question is that I was poking through the Qtc docs, and saw
> this:
>
>
> Documentation
>
>    data Object a
>
> Constructors
>
>    QObject !(ForeignPtr a)
>
> I am not sure how Haddock works. Is this telling me that an Object
> constructor takes one argument, which is of type QObject, where QObject is
> a type constructor that takes !(ForeignPtr a)? Or is this saying it takes
> two arguments, a QObject and a !(ForeignPtr a). That latter makes more
> sense I guess. What does the ! mean?

It tells you that the (Object a) datatype has a data-constructor called QObject (I know
you already figured that out) which takes one argument of type (ForeignPtr a).
However, the constructor's argument type has a bang (!), which means that the constructor
is strict in its argument.

For nonstrict constructors (data Ob a = Con a), you can happily create a value

Con _|_

which will be a nice and harmless citizen until you try to look at its contents. For
example,

let x = Con undefined in x `seq` 3

returns 3, only

let x = Con undefined in
     case x of
       Con y -> y `seq` 3

will raise an exception.
If you make your constructor strict (data Thing a = SCon !a), it doesn't accept a bottom,
the strict constructor evaluates its argument to weak head normal form, if it encounters a
bottom, an exception is raised.
So,
Con _|_ /= _|_
but
SCon _|_ == _|_
>
> Thanks,
> Mike