![]() ![]() ![]() There are lots of variations and generalisations of this type, but this is the basic form. ![]() Here’s the magic type for expressions with lexical scope: data Expr a = ClosedExpr a | OpenExpr Name (Expr (Value -> a)) For example:Įxpressions with no free variables are “closed”, those with one or more are “open”. An expressions has some set of free (unbound) variables, which can then be bound in composition with other expressions. if we want to, we could also pass through errors that are being used as arguments, making all functions “strict”. Note how we pass through errors that are being used as functions. Vapply _ _ = VError "not a function" - or a more informative error message It’ll probably look something like this: vapply :: Value -> Value -> Value This is a function takes a “function” value and an “argument” value and applies them. Note that we’re handling errors as a kind of value ( VError), but there are other approaches to error-handling. Since the language is based on the lambda calculus, it will need to include a constructor for functions. You’ll need a type to represent the values your language works on, a sum of all the types of values you want to work with. I won’t spend much time on syntax, but for familiarity, any examples of the language itself will look roughly like Haskell where possible. pure, meaning that functions have no side-effects, although it’s not hard to adapt this to IO or some other monad if you want.dynamically-typed (or unityped as Robert Harper might say), meaning that there is one type for all values that is a sum of various useful types for text, numbers, lists, etc., and most importantly, functions,.lexically scoped, meaning that names are resolved at their use in the source code,.based on the lambda calculus, with variable references, function applications, and function abstractions,.Assuming you are competent in Haskell, I’ll walk you through the basic steps of writing an interpreter for such a language, and you can fill in the details. And as it turns out, they are not that difficult to write. Domain-specific languages are very useful, and ones that allow computation are more useful still. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |