## Static type inference & late binding?

[Edit: Previous LtU discussions. I guess I'm hoping to learn if there is anything new, new, new!]

Where might I find a language that infers static types (a la Haskell, SML, O'Caml) and yet also allows for late binding (a la Smalltalk, Lisp). I know some folks have tried to do it for Smalltalk and even for Lisp, but none are particularly 'main stream'. Are there any other obvious things I'm failing to recall?

Ah, the Merd page led me to soft typing! The dates on all the papers in Google hits look old. The only thing that appears to still be kicking is PLT's Mr. Spidey debugger. Has anybody had experience with it, per chance?

## Comment viewing options

### I found a reference to MrFlow

I found a reference to MrFlow (not Mr. Flow or Mr. Spidey, it looks like) which is unfortunately apparently perpetually "coming soon." I guess I'd also like a compiler-style interaction where I could get a report; it looks like MrSpidey and MrFlow require you to look at things via the GUI to notice what it figured out?

### MrFlow

I talked to the guy responsible for MrFlow. He unfortunately has had severe wrist problems from typing.. He hopes to get it out this year.
I'll point him to this message to see if he has anything to say.

### Depending on where you want the dynamism

Alice ML definitely qualifies as a static type inference language. On the other side, Alice ML supports what it calls "Open Programming" with packages. Package types are inferred at run time when they are unpacked or unpickled.

### Re: Alice

Great, thanks for the note! Since I have such fond memories of using SML in college (strange to have fond memories of any class from college...), Alice seems super cool to me. I'd be interested in using it on the server side of things, where using concurrency would possibly be worth the trouble. (On the client-side of things i.e.: for a networked video game I'm learning Scala since it can leverage Java libraries.)

### Ousp, wrong guy

Sorry Daniel. My type project is not related with MrFlow in any way. I'm sorry if I gave you that impression. Philippe Meunier built MrFlow. You should contact him if you want more information on his release plans.

### What is late binding?

Or, why doesn't Haskell count? As far as I know, if function is used polymorphically the compiler has to pass along a type indexed dictionary of functions which get dispatched at runtime. (Someone in the know might want to provide a more precise explanation). In other words, the following program...

data Foo = F Double Double deriving (Show, Eq)

instance Num Foo where
(F a b) + (F c d) = F (a+b) (c+d)

main = do let x = F 1.0 1.0
let y = F 2.0 3.0
putStrLn $"x + y = " ++ (show$ x + y)
putStrLn $"x * y = " ++ (show$ x * y)


...dies with a runtime error...

x + y = F 2.0 5.0
late_binding: late_binding.hs:3:0: No instance nor default method for class operation GHC.Num.*


...because there's no instance for '*' defined. I suppose you want to be able to extend the dictionaries at runtime. Maybe hs-plugins is what you're looking for? At least you get runtime eval...

import System.Eval.Haskell

main = do i <- eval "1 + 6 :: Int" [] :: IO (Maybe Int)
if isJust i then putStrLn (show (fromJust i)) else return ()


Or you can always use dynamic types provided by Data.Dynamic ...

import Data.Dynamic

main = do
let n = map (dynApply factorial)
[toDyn (4::Int),toDyn (5::Int),toDyn ("six"::String)]
print \$ map (fmap (\x -> fromDyn x (0::Int))) n

factorial = toDyn (fac::Int->Int)

fac 0 = 1
fac n = n*(fac (n - 1))



Thank you for the info! I am clearly entirely too clueless when it comes to the less-than-blatently-obvious details of Haskell. Using Haskell would be great (assuming I can some day get it working on one of my machines).

I think I was also mentally meaning to ask a related question, but totally failed to mention it: I'm wondering how static type inference and late binding can really get along together, and what the latest research is on that. Getting runtime errors gives me the heebie-geebies, so I wonder to what extent the static typing can narrow the range for late binding - it would be a balancing act between not narrowing things too much in the 'compile' phase vs. being so lenient that you end up with something as gross as duck typing?

### You can use static typing to

You can use static typing to force you to recover from any type errors on late bindings. Type classes also make for a rather neat form of (mostly compile time) duck typing.

### first list your mainstream languages

infers static types... allows for late binding... but none are particularly 'main stream'

Seems like you have an additional requirement that the language be 'main stream' - so let me suggest that you list the languages you consider to be 'main stream' and then eliminate all those that don't provide type inference or allow late binding.

### Re: 'main stream'

Good point. My apologies if 'main stream' is severely subjective! I should have used a longer description along the lines of "is under active development and support, and has an active community around it." I don't think the Smalltalk stuff counts, and I suspect that the Qi stuff, although very interesting to me, isn't widely used. For sure, anything from the PLT group falls into the 'is used' category for me, if only because one of the other programmers in my office uses it on nights and weekends :-)

(Another language that comes to mind is Clean, if their 'Dynamics' count? But they, too, seem a little less widely used and their IDE is not something I like to use.)

### Not grounded in current reality

As an aside: The problem with checking dynamic behaviour is, at least, that there is so much to possibly check. A possible solution, some day, would be the application of quantum computers to search the entire (or some large amount of the) dynamic state space for violations of defined rules. Come on, science!

### Functional Programming with Dynamic Binding

• Functional Programming with Dynamic Binding
Dynamic binding is a runtime operation which looks up some names in some environments: examples are quote and eval in LISP or object-oriented message passing. We present a functional language, in the spirit of ML or Haskell, which supports dynamic binding. At the surface level, the language supports constructs such as extensible records, variants, extensible case selection, quoted terms, and can encode various forms of objects. The underlying execution model is a lambda-calculus with name-based (labels, keywords) parameter passing. The type system supports subtyping, through an extension of Hindley-Milner type inference with recursively constrained types.