Dynamic linking of Haskell modules?

2002-01-24 Thread senganb

I'd like to be able to dynamically load Haskell code
from a "plugin" binary file into a Haskell application,
just as I can dynamically load .so files into a C application.

Since ghci does this, I thought I could copy its implementation
but after looking into it, it's very complicated. I notice
that OCaml can do this (http://algol.prosalg.no/~malc/scaml/)

The only simple solution I can think of is to use FFI to export
the objects in the .so file as following the C interface, and then
importing them into the main Haskell application as "C functions",
but the extra marshalling is ugly.

Has anyone solved this problem?
Are there any plans to support this in the future in ghc or a
third party library?

Sengan


___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: Intro to Functional Prog. by Bird, Section 2.5

2002-01-02 Thread senganb

> data Either' a b =  Left' a | Right' b
> 
> case' :: (a->g, b->g) -> Either' a b -> g
> case' (f, g) (Left' x) = f x
> case' (f, g) (Right' y) = g y
> 
> plus' :: (a->b , g->d) -> Either' a g -> Either' b d
> plus' (f,g) = case' (Left' f, Right' g)

case' takes as first argument a tuple of functions as described by the type
"(a->g,b->g)":
 * a->g is a function taking something of type a and returning something of type g.
 * b->g is a function taking something of type b and returning something of type g.
 * (x,y) is a tuple taking something of type x as first element, and something of
   type y as second element.
 * Substitute x = a->g and y = b->g and you get a tuple of functions returning the
   same type g but taking as input types a and b respectively.

case' takes as second argument something of type (Either' a b) which has 2 possible
forms: an object (Left' x) or an object (Right' y). The following line states that
the object x must be of type a, and the object y must be of type b:
> data Either' a b =  Left' a | Right' b

Take your function plus':

> plus' :: (a->b , g->d) -> Either' a g -> Either' b d
> plus' (f,g) = case' (Left' f, Right' g)

Uncurry it (convert it such that all its arguments are explicit):

plus' (f,g)   = case' (Left' f, Right' g)
=>  plus' (f,g)   = \x -> case' (Left' f, Right' g) x
=>  plus' (f,g) x = case' (Left' f, Right' g) x

Notice that you are passing as first argument to case',
not a tuple of functions, but a tuple of objects of type
(Either i j). This is what the interpreter is telling you:

> --ERROR sec2-5.hs:8 - Type error in application
> --*** Expression : case' (Left' f,Right' g)
> --*** Term   : (Left' f,Right' g)
> --*** Type   : (Either' (d -> e) f,Either' g (h -> i))
  ^^^^^^
> --*** Does not match : (a -> b,c -> b)
  ^

Look at the types of plus' and case', and at case' 's definition
to figure out the solution. It's not difficult.

Sengan


___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: Learning Haskell and FP

2000-12-28 Thread senganb

>  * The Design Patterns Haskell Companion
>by [someone(s) reading this list?]

I agree except I would also like to see more on Haskell space-leaks and how to
find them. Lazyness is great for structuring programs and garbage collection
helps rapid prototyping immensely. However it makes it difficult to find the
cause of that 128Mb heap overflow once you have 2000 lines of code. Yes the
profiler gives you an idea of which function is using a lot of heap, but not
exactly where. E.g. I rewrote my monads ultra stritly and the heap consumption
fell by half, even though I'm not convinced being so strict isn't just masking
some other problem:

>(MN c1) >>= fc2 = MN $ \s0 -> case c1  s0 of { (r1,io1,s1) ->
>  case fc2 r1 of { (  MN c2  ) ->
>  case c2  s1 of { (r2,io2,s2) ->
>  (r2,io1 >> io2,s2)  }}}

Such a "community written book" might be good for
http://www.lightandmatter.com/cgi-bin/asbrowsesubject.cgi?class=Q

Sengan


___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe