dynamic types

Richard Uhtenwoldt ru@river.org
Tue, 07 Jan 2003 19:56:24 -0800


Hal Daume III writes:
>You are correct.  You can't say:
>
>  let x = if ??? then () else (5::Integer)

I meant to ask if when you do this next

   let x = if ??? then toDyn () else toDyn (5::Integer)

can you then dispatch on x's type.
In my sample code, I forgot the toDyns.  eek!

Anyway, this next line in your post showed me I do not even need
Dynamic or any other library.  Meets my needs.  I feel a little dumb
for not thinking of it myself.  (Perhaps that's what I like about
Haskell: it regularly makes me feel dumb.)

> data Univ = UUnit () | UInteger Integer | UDouble Double | ...

Thank you for the info, Hal Daume.

P.S.  Here's some simple tested code that demonstrates dispatching on
the Univ type:

data Univ = UUnit () | UInteger Integer | UOther 

main=do
    command<-getLine
    --make an object of Univ type:
    let
        object::Univ
        object=case command of
            "integer"->UInteger (5::Integer)
            "unit"->UUnit ()
            _->UOther 
    --now dispatch on it:
    case object of
        UUnit ()->putStrLn "void type detected"
        UInteger (a::Integer)->putStr "Integer type detected, namely ">>
            print a
        _->putStrLn 
            "detected a type the programmer doesnt want to bother with"
    main