[Haskell-beginners] FFI, Foreign.Marshal.Array, etc.

Alexey Beshenov al at beshenov.ru
Wed Nov 26 18:40:56 EST 2008


On Thursday 27 November 2008 01:16:17 Alexey Beshenov wrote:
> Something like this:
>
> foreign import ccall "linear.h solve_sys" lSolve :: Ptr (Double) ->
> Int -> Ptr (Double) -> IO (Int)
>
> solveSys :: [[Double]] -> [Double] -> IO()
> solveSys a b = do
>                   aptr <- newArray (concat a)
>                   bptr <- newArray b
>                   sol <- lSolve aptr n bptr
>                   x <- peekArray n bptr
>                   free aptr
>                   free bptr
>                   print x
>                where n = length a
>
> Does the trick, but I wonder is there a way to get a function
> returning [Double]...

Eh, I have to do unsafePerformIO.

Sorry about that, I'm quite new to Haskell :-I

-- 
Setting Orange, Aftermath 38 YOLD 3174
Alexey Beshenov  http://beshenov.ru/



More information about the Beginners mailing list