Re: [Haskell-cafe] FFI question - FunPtrs to top-level functions

2011-08-18 Thread kyra

On 8/18/2011 6:49 AM, Antoine Latter wrote:

Hi Haskell,

I have a question about the Haskell FFI and creating FunPtrs to
Haskell functions.

Does anyone have any recommendations for when I have a top-level
function that I would like to pass to a C function as a function
pointer (that is called via a foreign import)?

I know that the FFI provides the wrapper foreign import I can use to
wrap Haskell functions, but then I would need to jump through hoops to
manage the liefetime of of the FunPtr wrapper. If I were closing over
interesting state I would want this - but the function
(side-effectfully) operates only on its arguments (and the Haskell
RTS, of course).

Is it okay to place an unsafePerformIO $ mkWrapper myFunc as a
top-level declaration, or am I journeying into uncharted lands?

Is there something clever I can do with foreign exports and foreign
imports, or is this just making things too complex?

Thanks,
Antoine

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

You can export and reimport the same function with no wrapper needed. 
For example:


foreign export ccall foo :: ...
foreign import ccall  foo fooptr :: FunPtr (...)

Cheers,
Kyra

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ghc panic when compiling blaze-builder

2010-11-20 Thread kyra

On 11/21/2010 3:20 AM, JosИ Romildo Malaquias wrote:

When compiling blaze-builder-0.2.0.1 with ghc-7.0.1 on my ~amd64 gentoo
system, I am getting the shown below.

Any clues?

Romildo


[...]
Building blaze-builder-0.2.0.1...
[1 of 8] Compiling Blaze.ByteString.Builder.Internal ( 
Blaze/ByteString/Builder/Internal.hs, 
dist/build/Blaze/ByteString/Builder/Internal.o )
ghc: panic! (the 'impossible' happened)
   (GHC version 7.0.1 for x86_64-unknown-linux):
dsLet: unlifted


Look here: http://hackage.haskell.org/trac/ghc/ticket/4498
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Will GHC 6.14 with LLVM use LLVM C compiler to compile external C Libraries

2010-09-09 Thread kyra
I wonder if llvm-gcc supports it's own (gcc) extensions. If it supports 
then there is no need to stuck in clang right now.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] How to derive instance for type without exported constructor?

2009-09-04 Thread kyra

Miguel Mitrofanov wrote:
Well, normally - you can't (unless there is some equivalent to the 
constructor exported).


But there is a trick. You can use generic classes:

{-# OPTIONS_GHC -fglasgow-exts -XGenerics -package lang #-}
import Generics
class Binary' a where
  put' :: a - Put
  get' :: Get a
  put' {| Unit |} Unit = return ()
  get' {| Unit |} = return Unit
  put' {| a :+: b |} (Inl x) = putWord8 0  put' x
  put' {| a :+: b |} (Inr y) = putWord8 1  put' y
  get' {| a :+: b |} =
do w - getWord8
   case w of
 0 - liftM Left get'
 _ - liftM Right get'
  put' {| a :*: b |} (x :*: y) = put' x  put' y
  get' {| a :*: b |} =
do x - get'
   y - get'
   return $ x :*: y
instance Binary' Int32 where
  put' = put
  get' = get
instance Binary' StdGen
instance Binary StdGen where
  put = put'
  get = get'



Isn't it to define an isomorphic type and unsafeCoerce to it pretty much 
equivalent?


At least the following simplest example works just fine:

module Main where

import Unsafe.Coerce

class Test a where
  test :: a - Int

data Foo = Foo Int Int

data Bar = Bar Int Int

instance Test Bar where test (Bar a b) = a + b

instance Test Foo where test foo = test (unsafeCoerce foo :: Bar)

main :: IO ()
main = print $ test (Foo 123 345)


Cheers,
Kyra

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Looking for Haskellers on Windows

2009-01-10 Thread kyra

John Goerzen wrote:

GЭnther Schmidt wrote:
Kyra I've tried any sort of values to any sort of columns. I tried insert  
into somesinglecolumntable (someNumbercolumn) values (?) [toSql 5] ...  
and so on.


So I'm not certain at all the error message does actually give the right  
clue.


It just blows no matter what.


It seems, I've managed to track down the issue.

Access ODBC driver doesn't support sqlDescribeParam.

bindCol (Database/HDBC/ODBC/Statement.hsc) contains the following stub 
for this:


  do poke pdtype #{const SQL_CHAR}
 poke pcolsize 0
 poke pdecdigits 0

This does not work.

I've made an experiment replacing 'poke pcolsize 0' with 'poke pcolsize 
255'. Now all integer or varchar bindings work!


It seems simpleSqlColumns or something similar must be used.

Cheers,
Kyra
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Trouble with FFI on Windows2000...

2008-12-21 Thread kyra

Serge LE HUITOUZE wrote:

I do the following:
  

dlltool -d cproj1.def -l libcproj1.a
ghc --make testFFI_2.hs -optl-lcproj1 -optl-L.



This seems fine, since it produces a testFFI_2.exe.
However, executing it, I get a MSWindows error box with a message
that looks like (approximate translation): 
DLL (null) not found on specified path


At first, I didn't have the LIBRARY directive in the .def file,
so I thought that was the reason for the (null) appearing in the
message. But adding said directive didn't change anything...

  

dlltool -d cproj1.def -l libcproj1.a -D cproj1.dll
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FFI and struct arguments

2008-07-17 Thread kyra

Felipe Lessa wrote:

Hi,

I tried googling and searching the haskellwiki about this but wasn't
lucky enough. My question is: is there a way to send struct arguments
to C functions via the FFI or do I need to create a C wrapper? I guess
there isn't, and while I can live without it, I'd like to leave no
doubt.
  

Sometimes there is such a way. See below.

Details:

I have something like


typedef struct vect {
float x,y;
} vect;

void func(vect v);
  

For most architectures stack layout of

void func(vect v);

and

void func(float x, float y);

is exactly the same, so for FFI purposes this 'func' can be declared as 
something like:


foreign import ccall unsafe :: Float - Float - IO ()


Cheers,
Kyra

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] FFI and struct arguments

2008-07-17 Thread kyra

If the struct is passed by reference of course then you're fine, but if
it's by value then you need a C wrapper. The reason is because it's
beyond the scope of the FFI to know the structure layout and how to map
that to haskell types. That's the domain of FFI pre-processors. However
I don't know of any FFI pre-processors that help in this case. Passing C
structs by value seems to be pretty rare in exported C APIs.


Yes, but programmer *knows* the structure layout, so she usually can 
emulate it with a sequence of primary ffi type arguments. It's pretty 
trivial for the original example (see my previous post on this subj) and 
can be extended further. For example, in my homebrew COM library I 
pretty successfully marshall 16-byte Variants *by value* by means of two 
consecutive legal Word64 arguments.


Cheers,
Kyra

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell DLL crashes Excel

2006-09-22 Thread Kyra

Andreas Marth wrote:


type BSTR8 = Ptr Word8

createBSTR8 :: String - IO BSTR8
createBSTR8 s = do
   let
 len :: Word32 = fromIntegral (length s)
 low_l :: Word8 = fromIntegral (len .. 0x)
 low_h :: Word8 = fromIntegral (shiftR len 8 .. 0x)
 high_l :: Word8 = fromIntegral (shiftR len 16 .. 0x)
 high_h :: Word8 = fromIntegral (shiftR len 24 .. 0x)
   arr - newArray ([low_l,low_h,high_l,high_h] ++ map (fromIntegral .
fromEnum) s ++ [0])
   return $! plusPtr arr 4


Use SysAllocString... family. Also, remember they (by convention) have 
to be released from the client side.


Cheers,
Kyra


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell DLL crashes Excel

2006-09-22 Thread Kyra

Kyra wrote:
Use SysAllocString... family. Also, remember they (by convention) have 
to be released from the client side.


Oops, they = such allocated BSTRs.

Cheers,
Kyra
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] using of data types as kinds

2005-11-22 Thread kyra

Bulat Ziganshin wrote:


Hello Simon,

Tuesday, November 22, 2005, 8:17:38 PM, you wrote:

SPJ I have not written anything about what I plan to do in GHC, but
SPJ basically it amounts to allowing you to use a data type as a
SPJ kind.  Busy doing GADTs and impredicativity at the moment though

Simon, i can't download file

http://research.microsoft.com/~simonpj/papers/boxy/boxy-pldi.ps.gz

reffered at http://research.microsoft.com/~simonpj/papers/boxy/


 


Google gives http://www.cis.upenn.edu/~dimitriv/boxy/boxy.ps
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Oracle + Haskell advice?

2005-08-19 Thread kyra

Keean Schupke wrote:

Well, I'll put my hand up, I use Haskell with databases and web 
stuff... Unfortunately when I started the common tools were not 
available. I have a home-grown Haskell-Servlet server, with monadic 
continuation based HTML composition and a HaskellDB like database 
layer. It all works very well, but being written for internal use (and 
me being lazy) it has only those features that I need. It is however 
designed as an integrated Web-Application platform... I was 
considering releasing it - but since I started other projects like 
HaskellDB restarted, WASH was written, HSQL started to support unix, 
and somebody added plugins to the Haskell Web-Server - So I didn't 
bother, although I am still using it myself...


Still I now know that HaskellDB has significant limitations, and the 
relational algebra approach I took is far more robust and flexable...


I don't have time to take this from a usable but incomplete project to 
a fully implemented API - what I mean here is that not all ODBC calls 
are implemented, some SQL features might be missing, some tags are not 
defined... not all HTTP requests and errors are generated, oh and 
there's no documentation. If anyone were interested in 
using/contributing I could give CVS access to the code.


   Keean.


Yes, I'm definitely interested in evaluating/using/contributing your 
framework.


Regards, Kyra
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe