[Haskell-cafe] embedding Haskell: problematic polymorphism

Claus Reinke claus.reinke at talk21.com
Wed Jul 11 21:22:06 EDT 2007

> Say I have 3 boxes:
> Box 1:  [1,2,5,3]        :: [Float]
> Box 2:  reverse          :: [a] -> [a]
> Box 3:  putStrLn . show  :: (Show b) => b -> IO ()
> I wonder, is it possible to create these boxes separately at runtime 
> (each box being compiled/loaded separately with hsplugins), then connect 
> them together like {Box 1}=>{Box 2}=>{Box 3} (with a wrapping layer 
> doing appropriate type checking/error reporting), or does the whole 
> thing need to be compiled statically to generate specialized variants of 
> the polymorphic functions?  As hinted in #haskell :

haskell itself doesn't offer support for this. one reason why a proper
integration of Dynamic/typecase, together with orthogonal persistence
(napier88, tycoon), or first-class i/o (clean), or dynamic packages (alice), 
into the language would be nice to have..

depending on your application, though, you might be able to pretend
that you are ghci, by using the ghc api to turn your program into a 
controller for a ghci session. or look in the ghci sources for clues on
how to circumvent haskell's limitations to achieve what you want.
because ghci can do something like this (here from the prompt, but
the definitions could also be loaded from compiled modules):

    Prelude> :set -fno-monomorphism-restriction
    Prelude> let box1 = [1,2,5,3]::[Float]
    Prelude> let box2 = reverse :: [a]->[a]
    Prelude> let box3 = putStrLn . show :: Show b => b -> IO ()
    Prelude> :t box1
    box1 :: [Float]
    Prelude> :t box2
    box2 :: [a] -> [a]
    Prelude> :t box3
    box3 :: (Show b) => b -> IO ()
    Prelude> box3 $ box2 box1


ps: using haskell as a coordination layer over c boxes would
    be more conventional.. if you want to provide haskell
    components for a c-based framework, the latter isn't
    going to know about haskell types anyway, is it?

More information about the Haskell-Cafe mailing list