Link to Snippet

The Haskell const function

The const function is simple, but you can use it to make your code more legible. In this example we convert a unary function to a function of arity 2 (that ignores the second argument). Also by using the flip function from Haskell (which is equally easy to define) you can ignore the first argument.

// Code taken from a toy interpretertypeExp=// ...// Lambdas are expressed as F# an function that takes a list of Exps and an env
| Lambdaof (Explist->Env->Exp)
// ...andEnv= (string*Exp) list// Built-ins receive evaluated arguments so they don't care about the env.// By composing the function we get with ct we're basically converting a function// of arity 1 to a function of arity 2 that just ignores its second argumentletbuiltinf=Lambda (f>>ct)