embedding Haskell: problematic polymorphism

Hi people, I'm embedding Haskell into a C program with a "stateful objects with message passing" paradigm [0]. I want to make "boxes" with useful functions, then connect them together within the C program. I know how to build a working version using Data.Dynamic, but that loses polymorphism [1]. 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 : <quicksilver> ClaudiusMaximus: I don't think anything will allow you to pass around polymorphic values. They're an illusion of the type-checker, in a sense. Thanks for any insights, Claude [0] http://puredata.info [1] Data.Dynamic> (fromDynamic (toDyn (3.5::Double)))::(Typeable a => Maybe a) <interactive>:1:0: Ambiguous type variable `a' in the constraint: `Typeable a' arising from instantiating a type signature at <interactive>:1:0-59 Probable fix: add a type signature that fixes these type variable(s) -- http://claudiusmaximus.goto10.org

On Wed, Jul 11, 2007 at 05:45:40PM +0000, Claude Heiland-Allen wrote:
Hi people,
I'm embedding Haskell into a C program with a "stateful objects with message passing" paradigm [0]. I want to make "boxes" with useful functions, then connect them together within the C program. I know how to build a working version using Data.Dynamic, but that loses polymorphism [1].
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 :
<quicksilver> ClaudiusMaximus: I don't think anything will allow you to pass around polymorphic values. They're an illusion of the type-checker, in a sense.
There is nothing intrinsically impossible with a Data.Dynamic like interface for polytypic values. Good luck writing toDyn and fromDyn without compiler support, however. Stefan

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 [3.0,5.0,2.0,1.0] claus 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?
participants (3)
-
Claude Heiland-Allen
-
Claus Reinke
-
Stefan O'Rear