3 ms·
Are you really doing "type inference like Haskell"? -- somehow I doubt that you're actually doing Hindley-Milner. I'd wager that you're doing something more li
by blasdel 18y ago
Are you really doing "type inference like Haskell"? -- somehow I doubt that you're actually doing Hindley-Milner.
I'd wager that you're doing something more like what csc and javac do to give error messages, and which C# 3.0 uses to support the var keyword.
- crux_ 18y agoHindley-Milner is easy, as long as you throw either subtyping or recursion out the window. ;) (IIRC) (Doesn't C# basically use HM to support the var keyword, anyway? That's what I'd do.)
- olavk 18y agovar in C# is only allowed for local variables, which means you can easily infer the type by analysing the assigment expression, which will always depend on known types. For example method parameters are always explicitly typed. Haskell style type inference is more tricky, since it also tries to infer the type of function signatures from the different contexts where the function is called. This can lead to circular type dependencies.
- crux_ 18y ago"Easily"? I suspect that since C#3 offers lambda expressions that you'd need to use something close to (although probably different from) full H-M inference... in fact, it seems like it may need to be nearly as complicated as Scala's type inference, which is saying something. =)
- olavk 18y agoI don't think you can assign a lambda expression to a var in C#.