Tell HN: F# Rocks
type Expr =
| Num of int
| Add of Expr * Expr
| Mul of Expr * Expr
| Var of string
let rec Evaluate (env:Map<string,int>) exp =
match exp with
| Num n -> n
| Add (x,y) -> Evaluate env x + Evaluate env y
| Mul (x,y) -> Evaluate env x * Evaluate env y
| Var id -> env.[id]
let envA = Map.ofList [ "a", 1; "b", 2; "c", 3 ]
let expT1 = Add(Var "a",Mul(Num 2,Var "b"))
let resT1 = Evaluate envA expT1
=> 5
5 comments
[ 2.8 ms ] story [ 19.9 ms ] threadF# is a neat language. I'm sort of surprised he went with the type system rather than computation expressions/async workflows, which are my favorite feature. They aren't unique (they're monads) but the syntax is nice. I'd happily code in F# if I had a reason to write .NET code.