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.  Easier alternatives to existential types? (Emile Melnicov)
   2.  FFI: FinalizerPtr and freeHaskellFunPtr (Patrick LeBoutillier)
   3. Re:  Easier alternatives to existential types? (Brent Yorgey)
   4.  some help on do and preservingMatrix (Zsolt Ero)
   5. Re:  Easier alternatives to existential types? (Stephen Tetley)
   6.  fail: wxhaskell with cabal (Josh Bronson)
   7. Re:  fail: wxhaskell with cabal (Daniel Fischer)
   8. Re:  fail: wxhaskell with cabal (Chadda? Fouch?)
   9.  Questions on GHCi 6.10.4 + general questions (Lev Broido)


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

Message: 1
Date: Thu, 26 Nov 2009 22:01:32 +0400
From: Emile Melnicov <[email protected]>
Subject: [Haskell-beginners] Easier alternatives to existential types?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="us-ascii"

> Well, yes, I know that almost certanly that was not what you 
> were thinking when you wrote the question.

Sorry, I should include my code snippet indeed.

data Chunk a = Chunk { cHeader :: Header, cData :: a }
data Header = Header { hID :: Word32, hSize :: Word32 }
data Format = Format { ... }
newtype Data = Data ByteString

h :: Header
...
formatChunk :: Chunk Format
...
dataChunk :: Chunk Data
...

data Container a =
    Container { ctHeader :: Header, ctType :: Word32,
                ctContent :: [Chunk a] }

-- Very naive.
containerChunk :: Container a
containerChunk = Container h 42 [formatChunk, dataChunk]

I'm interested in common pattern used in Haskell for this kind 
of problems.

> If you really want existentials, though, I'd recommend using 
> GADT syntax

OK, I'll try it out. I'm already know about GADT's, but can't 
catch the difference between regular Algebraic Data Types and 
Generalised ones (in terms of disjoint union etc.). Can you 
recommend some paper where GADT's are described, but without 
very deep mathematical entities?


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

Message: 2
Date: Thu, 26 Nov 2009 13:23:53 -0500
From: Patrick LeBoutillier <[email protected]>
Subject: [Haskell-beginners] FFI: FinalizerPtr and freeHaskellFunPtr
To: beginners <[email protected]>
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I'm trying to write a binding to a C library, and so far here is the
code I have:


{-# LANGUAGE ForeignFunctionInterface #-}
import Foreign.Ptr
import Foreign.ForeignPtr

newtype C_mlp_context = C_mlp_context (Ptr C_mlp_context)
data MLPContext = MLPContext !(ForeignPtr C_mlp_context)
                    deriving (Show)

foreign import ccall "wrapper"
  makeFinalizer :: (Ptr a -> IO ()) -> IO (FinalizerPtr a)

foreign import ccall unsafe "mlp.h mlp_context_new" c_new :: IO (Ptr
C_mlp_context)
new :: IO MLPContext
new = do
  mlp_context <- c_new
  fin <- mlp_context_finalizer
  fctx <- newForeignPtr fin mlp_context
  return $ MLPContext fctx

mlp_context_finalizer :: IO (FinalizerPtr C_mlp_context)
mlp_context_finalizer = do
  makeFinalizer $ \ctx -> do
    c_delete ctx

foreign import ccall unsafe "mlp.h mlp_context_delete" c_delete :: Ptr
C_mlp_context -> IO ()

main = do
  ctx <- new
  putStrLn $ show ctx


This seems to work as expected, but I read that I'm supposed to call
freeHaskellFunPtr on the finalizer
when I'm done with it.  However I don't know how I can do this since
it is called by the GC...

Can anyone offer any advice?


Thanks,

Patrick

-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada


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

Message: 3
Date: Thu, 26 Nov 2009 13:41:41 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Easier alternatives to existential
        types?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Thu, Nov 26, 2009 at 10:01:32PM +0400, Emile Melnicov wrote:
> > Well, yes, I know that almost certanly that was not what you 
> > were thinking when you wrote the question.
> 
> Sorry, I should include my code snippet indeed.
> 
> data Chunk a = Chunk { cHeader :: Header, cData :: a }
> data Header = Header { hID :: Word32, hSize :: Word32 }
> data Format = Format { ... }
> newtype Data = Data ByteString
> 
> h :: Header
> ...
> formatChunk :: Chunk Format
> ...
> dataChunk :: Chunk Data
> ...
> 
> data Container a =
>     Container { ctHeader :: Header, ctType :: Word32,
>                 ctContent :: [Chunk a] }

Do you *really* need 'Chunk' to be able to hold *any* type of data?
Or are there just a few alternatives?  If there are only a few
alternatives, you can put the alternatives together in a data type,
like this:

  data Content = ConH Header
               | ConD Data
               | ... other alternatives ...

  -- Chunk is no longer polymorphic
  data Chunk = Chunk { cHeader :: Header, cData :: Content }

Then you can pattern-match on things of type Content to see which sort
of content it is.  Existential types are not required unless you
really want to be able to put any type of content at all inside a
Chunk.

-Brent


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

Message: 4
Date: Thu, 26 Nov 2009 19:20:03 +0000
From: Zsolt Ero <[email protected]>
Subject: [Haskell-beginners] some help on do and preservingMatrix
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Could someone point me to some help on how does "do" work and how does
preservingMatrix?

I am trying to write a program starting from the OpenGL tutorial on
the wiki, but I never used do's.

My very basic question is that how do I generally repeat a command
many times? I understand "do" can do it, but it's not clear to me how
to use it and how it works.

So if I would like to write the following in one line, how could I write it?:
spiral 0.7
spiral 0.8
spiral 0.9
spiral 1.0

I don't understand in which cases I can use "map something
[0.7,0.8..1]" and in which cases I need do and how could I map using
do.

>From the tutorial, I could write this line, which works, but I don't
really know what does mapM_ and preservingMatrix do.

  mapM_ (\x -> preservingMatrix $ do
    scale x x (1::GLfloat)
    rotate (x*(200)) $ Vector3 0 0 (1::GLfloat)
    spiral ((sin(a/50))^2/2+0.5)
    ) $ ([0.5,0.6..1::GLfloat])

Zsolt


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

Message: 5
Date: Thu, 26 Nov 2009 20:01:19 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Easier alternatives to existential
        types?
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

2009/11/26 Brent Yorgey <[email protected]>:

> Do you *really* need 'Chunk' to be able to hold *any* type of data?
> Or are there just a few alternatives?  If there are only a few
> alternatives, you can put the alternatives together in a data type,
> like this:

Horribly enough, RIFF files do seem to support any type of data. A
processor of RIFF files would presumably parse chunk types that it
knows to expect and discard the rest.

Data.Dynamic from the Hierarchical libs shipped with GHC is another
option. Or a home brewed union type:


data Chunk = WaveChunk { ... }
           | AuChunk { ... }
           | UnintrepretedChunk ByteString

Best wishes

Stephen


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

Message: 6
Date: Thu, 26 Nov 2009 22:06:21 -0600
From: Josh Bronson <[email protected]>
Subject: [Haskell-beginners] fail: wxhaskell with cabal
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Greetings Haskellers,

Happy Thanksgiving! I'm using Ubuntu 9.10. I've performed the following steps:

# apt-get install ghc6

I then successfully did a local install of the Haskell platform in
~/mine/install

Now I am trying to get wxhaskell to install:

$ cabal install wx
[snip]
Configuring wxcore-0.12.1.2...
setup: Missing dependencies on foreign libraries:
* Missing C libraries: wx_baseu-2.8, wx_baseu_net-2.8, wx_baseu_xml-2.8
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.
cabal: Error: some packages failed to install:
wx-0.12.1.2 depends on wxcore-0.12.1.2 which failed to install.
wxcore-0.12.1.2 failed during the configure step. The exception was:
exit: ExitFailure 1

$ ls /usr/lib/libwx*
/usr/lib/libwx_baseu-2.8.so        /usr/lib/libwx_baseu_net-2.8.so.0.6.0
/usr/lib/libwx_baseu-2.8.so.0      /usr/lib/libwx_baseu_xml-2.8.so
/usr/lib/libwx_baseu-2.8.so.0.6.0  /usr/lib/libwx_baseu_xml-2.8.so.0
/usr/lib/libwx_baseu_net-2.8.so    /usr/lib/libwx_baseu_xml-2.8.so.0.6.0
/usr/lib/libwx_baseu_net-2.8.so.0

It looks like the libraries are there to me! any ideas?


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

Message: 7
Date: Fri, 27 Nov 2009 05:19:12 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] fail: wxhaskell with cabal
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="iso-8859-1"

Am Freitag 27 November 2009 05:06:21 schrieb Josh Bronson:
> Greetings Haskellers,
>
> Happy Thanksgiving! I'm using Ubuntu 9.10. I've performed the following
> steps:
>
> # apt-get install ghc6
>
> I then successfully did a local install of the Haskell platform in
> ~/mine/install
>
> Now I am trying to get wxhaskell to install:
>
> $ cabal install wx
> [snip]
> Configuring wxcore-0.12.1.2...
> setup: Missing dependencies on foreign libraries:
> * Missing C libraries: wx_baseu-2.8, wx_baseu_net-2.8, wx_baseu_xml-2.8
> This problem can usually be solved by installing the system packages that
> provide these libraries (you may need the "-dev" versions). If the
> libraries are already installed but in a non-standard location then you can
> use the flags --extra-include-dirs= and --extra-lib-dirs= to specify where
> they are. cabal: Error: some packages failed to install:
> wx-0.12.1.2 depends on wxcore-0.12.1.2 which failed to install.
> wxcore-0.12.1.2 failed during the configure step. The exception was:
> exit: ExitFailure 1
>
> $ ls /usr/lib/libwx*
> /usr/lib/libwx_baseu-2.8.so      /usr/lib/libwx_baseu_net-2.8.so.0.6.0
> /usr/lib/libwx_baseu-2.8.so.0    /usr/lib/libwx_baseu_xml-2.8.so
> /usr/lib/libwx_baseu-2.8.so.0.6.0  /usr/lib/libwx_baseu_xml-2.8.so.0
> /usr/lib/libwx_baseu_net-2.8.so    /usr/lib/libwx_baseu_xml-2.8.so.0.6.0
> /usr/lib/libwx_baseu_net-2.8.so.0
>
> It looks like the libraries are there to me! any ideas?

Perhaps cabal configure uses pkg-config to detect those libraries and you have 
no 
wx_***.pc in /usr/lib/pkgconfig ?
That occasionally happens to me.



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

Message: 8
Date: Fri, 27 Nov 2009 07:34:03 +0100
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] fail: wxhaskell with cabal
To: Josh Bronson <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Fri, Nov 27, 2009 at 5:06 AM, Josh Bronson <[email protected]> wrote:
> Now I am trying to get wxhaskell to install:
>
> $ cabal install wx
> [snip]
> Configuring wxcore-0.12.1.2...
> setup: Missing dependencies on foreign libraries:
> * Missing C libraries: wx_baseu-2.8, wx_baseu_net-2.8, wx_baseu_xml-2.8
> This problem can usually be solved by installing the system packages that
> provide these libraries (you may need the "-dev" versions). If the libraries
> are already installed but in a non-standard location then you can use the
> flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.
> cabal: Error: some packages failed to install:
> wx-0.12.1.2 depends on wxcore-0.12.1.2 which failed to install.
> wxcore-0.12.1.2 failed during the configure step. The exception was:
> exit: ExitFailure 1
>
> $ ls /usr/lib/libwx*
> /usr/lib/libwx_baseu-2.8.so        /usr/lib/libwx_baseu_net-2.8.so.0.6.0
> /usr/lib/libwx_baseu-2.8.so.0      /usr/lib/libwx_baseu_xml-2.8.so
> /usr/lib/libwx_baseu-2.8.so.0.6.0  /usr/lib/libwx_baseu_xml-2.8.so.0
> /usr/lib/libwx_baseu_net-2.8.so    /usr/lib/libwx_baseu_xml-2.8.so.0.6.0
> /usr/lib/libwx_baseu_net-2.8.so.0
>
> It looks like the libraries are there to me! any ideas?

The shared libraries are there, but did you check if the miscellaneous
headers were there ? In other word did you install the libwx*-dev
packages as invited to do by cabal in its error message ?

-- 
Jedaï


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

Message: 9
Date: Fri, 27 Nov 2009 10:44:34 +0200
From: Lev Broido <[email protected]>
Subject: [Haskell-beginners] Questions on GHCi 6.10.4 + general
        questions
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

Skipped content of type multipart/alternative-------------- next part 
--------------
A non-text attachment was scrubbed...
Name: DdrController.hs
Type: application/octet-stream
Size: 4273 bytes
Desc: not available
Url : 
http://www.haskell.org/pipermail/beginners/attachments/20091127/601789b6/DdrController.obj

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

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


End of Beginners Digest, Vol 17, Issue 30
*****************************************

Reply via email to