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: Multiple declarations of value constructor (Peter Hall)
2. Simple database application with gtk (Emanuel Koczwara)
3. calling virtual function from base class in FFI (using type
classes) (Nathan H?sken)
4. Fwd: FFI bindings to prodecure with an in-out parameter
(Matthew Hayden)
5. Re: Fwd: FFI bindings to prodecure with an in-out parameter
(Kyle Murphy)
6. Re: Fwd: FFI bindings to prodecure with an in-out parameter
(Matthew Hayden)
----------------------------------------------------------------------
Message: 1
Date: Wed, 19 Dec 2012 17:43:38 +0000
From: Peter Hall <[email protected]>
Subject: Re: [Haskell-beginners] Multiple declarations of value
constructor
To: Emanuel Koczwara <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<CAA6hAk7=qk2wddswft5p7fp7hhvpw3+jsrbmjxqhsqztbff...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Something like this?
class TwoValues a where
val1 :: a
val2 :: a
data MyTypeA = ValueA1 | ValueA2
data MyTypeB = ValueB1 | ValueB2
instance TwoValues MyTypeA where
val1 = ValueA1
val2 = ValueA2
instance TwoValues MyTypeB where
val1 = ValueB1
val2 = ValueB2
---
val1 :: MyTypeA -- ValueA1
val2 :: MyTypeB -- ValueB2
Peter
On 19 December 2012 15:52, Emanuel Koczwara <[email protected]>wrote:
> Hi,
>
> -- tests.hs
> data MyType1 = Value1 | Value2
> data MyType2 = Value1 | Value2
>
>
> Prelude> :l tests
> [1 of 1] Compiling Main ( tests.hs, interpreted )
>
> tests.hs:3:16:
> Multiple declarations of `Main.Value1'
> Declared at: tests.hs:1:16
> tests.hs:3:16
>
> tests.hs:3:25:
> Multiple declarations of `Main.Value2'
> Declared at: tests.hs:1:25
> tests.hs:3:25
> Failed, modules loaded: none.
>
> If so, how are numbers defined? I can use 1 :: Int or 1 :: Integer. Why
> not Value1 :: MyType1 and Value1 :: MyType2?
>
> Emanuel
>
>
>
>
> _______________________________________________
> 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/20121219/44144f21/attachment-0001.htm>
------------------------------
Message: 2
Date: Wed, 19 Dec 2012 22:26:37 +0100
From: Emanuel Koczwara <[email protected]>
Subject: [Haskell-beginners] Simple database application with gtk
To: "[email protected]" <[email protected]>
Message-ID: <1355952397.373.3.camel@emanuel-Dell-System-Vostro-3750>
Content-Type: text/plain; charset="UTF-8"
Hi,
I'm looking for an example of database application using gtk.
Here:
http://stackoverflow.com/questions/13949405/how-to-switch-from-qt4-mvc-to-gtk-mvc
user ntd pointed on libgda, but it looks like it's not covered by
Gtk2Hs.
Emanuel
------------------------------
Message: 3
Date: Wed, 19 Dec 2012 22:42:02 +0100
From: Nathan H?sken <[email protected]>
Subject: [Haskell-beginners] calling virtual function from base class
in FFI (using type classes)
To: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hey,
I am trying to write FFI bindings for a C++ class structure.
There is a base class with a bunch of (virtual) functions:
class Base {
virtual void func1();
virtual void func2();
}
Now I have many classes that derive from the base class, and I want to
be able to call func1 and func2 on them.
But I do not want to write an ffi function for every derived object and
every virtual function in base class. So I am trying:
data DerivedStruct
type Derived = Ptr DerivedStruct
class BaseFunc a
instance BaseFunc DerivedStruct
foreign import ccall "callBaseFunc1" func1 :: BaseFunc a => Ptr a -> IO ()
ghc gives me:
Unacceptable result type in foreign declaration:
BaseFunc a => Ptr a -> IO ()
When checking declaration:
foreign import ccall safe "static callBaseFunc1" func1
:: BaseFunc a => Ptr a -> IO ()
a) I do not get the error message. The return type is acceptable? Why is
IO () not acceptable?
b) How can I structure this?
Thanks!
Nathan
------------------------------
Message: 4
Date: Wed, 19 Dec 2012 21:49:19 +0000
From: Matthew Hayden <[email protected]>
Subject: [Haskell-beginners] Fwd: FFI bindings to prodecure with an
in-out parameter
To: [email protected]
Message-ID:
<CACxrBfz+Oc=ucvftj+3fodsyt1jcf__a4bzfqafzno1rdxu...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Dear Haskell Beginners,
I've gotten stuck developing an FFI binding to libspotify. One of the
functions I'm trying to bind to, sp_session_create, uses an in-out
parameter. Luckily I have an example of its usage here (in the definition
of main):
https://developer.spotify.com/technologies/libspotify/docs/12.1.45/jukebox_8c-example.html
It looks to me like they've allocated a pointer to an sp_session and then
passed a pointer to that to sp_session_create.
My best attempt tries to do the same but comes across a missing Storable
instance of the equivalent of the sp_session data structure. Because the C
definition of this struct is not exposed in the header files I can't work
out how to do it myself. The alternative of passing in an empty pointer
with the assumption that the procedure will allocate memory for us simply
segfaults.
I've put a source distribution up here (hit "raw" to download):
https://github.com/mrehayden1/hmdfm/blob/master/dist/hmdfm-0.1.0.0.tar.gz
The project can be built automatically with cabal and GHC with hsc2hs
installed.
Also if you like libspotify can be downloaded and automatically installed
(for *nix users I think at least) from here:
https://developer.spotify.com/technologies/libspotify/#download
Please, can anyone help?
Matthew Hayden
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20121219/0b9423f7/attachment-0001.htm>
------------------------------
Message: 5
Date: Wed, 19 Dec 2012 22:11:30 -0500
From: Kyle Murphy <[email protected]>
Subject: Re: [Haskell-beginners] Fwd: FFI bindings to prodecure with
an in-out parameter
To: Matthew Hayden <[email protected]>
Cc: [email protected]
Message-ID:
<CA+y6Jcyh++jMprgFMWgQT0vVkoOj7Ee76==b74ngnhuqey-...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
It's been a while since I've done anything with C, but if I'm reading
that right it's expecting a pointer pointer as the second argument. In
other words, it wants the address of a pointer that it will update
with a pointer to the instantiated instance of the session structure.
See if this helps:
http://www.haskell.org/haskellwiki/FFICookBook#Passing_pointer-to-pointer-to-thing
-R. Kyle Murphy
--
Curiosity was framed, Ignorance killed the cat.
On Wed, Dec 19, 2012 at 4:49 PM, Matthew Hayden
<[email protected]> wrote:
> Dear Haskell Beginners,
>
> I've gotten stuck developing an FFI binding to libspotify. One of the
> functions I'm trying to bind to, sp_session_create, uses an in-out
> parameter. Luckily I have an example of its usage here (in the definition of
> main):
>
> https://developer.spotify.com/technologies/libspotify/docs/12.1.45/jukebox_8c-example.html
>
> It looks to me like they've allocated a pointer to an sp_session and then
> passed a pointer to that to sp_session_create.
>
> My best attempt tries to do the same but comes across a missing Storable
> instance of the equivalent of the sp_session data structure. Because the C
> definition of this struct is not exposed in the header files I can't work
> out how to do it myself. The alternative of passing in an empty pointer with
> the assumption that the procedure will allocate memory for us simply
> segfaults.
>
> I've put a source distribution up here (hit "raw" to download):
> https://github.com/mrehayden1/hmdfm/blob/master/dist/hmdfm-0.1.0.0.tar.gz
> The project can be built automatically with cabal and GHC with hsc2hs
> installed.
>
> Also if you like libspotify can be downloaded and automatically installed
> (for *nix users I think at least) from here:
> https://developer.spotify.com/technologies/libspotify/#download
>
> Please, can anyone help?
>
> Matthew Hayden
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 6
Date: Thu, 20 Dec 2012 10:00:07 +0000
From: Matthew Hayden <[email protected]>
Subject: Re: [Haskell-beginners] Fwd: FFI bindings to prodecure with
an in-out parameter
To: Kyle Murphy <[email protected]>
Cc: [email protected]
Message-ID:
<cacxrbfyw_0nddrgxq2xpbjaqon5ad+ishkfegl3a3zhcecu...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
I'm glad my message finally got through!
I've fixed this one now. It was segfaulting because I was missing some
(undocumented) necessary data in one of the other arguments.
Passing it a Ptr (Ptr a) with alloca does the trick, and no need to
allocate memory for the opaque struct.
Thanks,
Matt
On 20 December 2012 03:11, Kyle Murphy <[email protected]> wrote:
> It's been a while since I've done anything with C, but if I'm reading
> that right it's expecting a pointer pointer as the second argument. In
> other words, it wants the address of a pointer that it will update
> with a pointer to the instantiated instance of the session structure.
> See if this helps:
>
> http://www.haskell.org/haskellwiki/FFICookBook#Passing_pointer-to-pointer-to-thing
>
> -R. Kyle Murphy
> --
> Curiosity was framed, Ignorance killed the cat.
>
>
> On Wed, Dec 19, 2012 at 4:49 PM, Matthew Hayden
> <[email protected]> wrote:
> > Dear Haskell Beginners,
> >
> > I've gotten stuck developing an FFI binding to libspotify. One of the
> > functions I'm trying to bind to, sp_session_create, uses an in-out
> > parameter. Luckily I have an example of its usage here (in the
> definition of
> > main):
> >
> >
> https://developer.spotify.com/technologies/libspotify/docs/12.1.45/jukebox_8c-example.html
> >
> > It looks to me like they've allocated a pointer to an sp_session and then
> > passed a pointer to that to sp_session_create.
> >
> > My best attempt tries to do the same but comes across a missing Storable
> > instance of the equivalent of the sp_session data structure. Because the
> C
> > definition of this struct is not exposed in the header files I can't work
> > out how to do it myself. The alternative of passing in an empty pointer
> with
> > the assumption that the procedure will allocate memory for us simply
> > segfaults.
> >
> > I've put a source distribution up here (hit "raw" to download):
> >
> https://github.com/mrehayden1/hmdfm/blob/master/dist/hmdfm-0.1.0.0.tar.gz
> > The project can be built automatically with cabal and GHC with hsc2hs
> > installed.
> >
> > Also if you like libspotify can be downloaded and automatically installed
> > (for *nix users I think at least) from here:
> > https://developer.spotify.com/technologies/libspotify/#download
> >
> > Please, can anyone help?
> >
> > Matthew Hayden
> >
> >
> >
> > _______________________________________________
> > 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/20121220/4ce51a77/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 54, Issue 29
*****************************************