comp Opium
This page is about Opium, a functional programming language.

Introduction

Opium is an experimental language in which I intend to write programs ... at some future point. I'm terribly unhappy with OCaml's syntax these days—it's simply hideous (no currying for constructors, strange prefix application for type parameters, no way to separate type annotations and definitions, difficult-to-read function declarations, and on and on and on.

Naturally, many solutions exist to this problem: I could simply switch to using Haskell (which I may well do at some point ...); I could write my own language and compiler, I could hack the OCaml parser, etc. –but– For the time being, I'm implementing Opium as an experiment to see how much can be done with what essentially amounts to a parser plus lineariser (Well, there's a *very* little bit of analysis / transformation, but it's almost trivial.).

Opium is, at this point, highly experimental, and can't really be used even for impractical / test programming, so I'm not going to release anything just yet.

News
Download
Demonstrations

A simple lambda-calculus interpreter.
data Exp = Var String
         | Lam String Exp
         | App Exp Exp
showExp :: Exp -> String
def showExp (Var x)     = x
  | showExp (Lam x e)   = "(lambda " +++ x +++ " . " +++ (showExp e) +++ ")"
  | showExp (App e1 e2) = "(" +++ (showExp e1) +++ (showExp e2) +++ ")"
type Env = [(String, Exp)]
eval :: Env -> Exp -> Exp
def eval g (Var x)     = assoc x g
  | eval g (App e1 e2) = case eval g e1 of
                         | Lam x e   -> let v = eval g e2 in
                                        eval ((x, v) : g) e
                         | otherwise -> failwith "invalid application."
  | eval g e           = e
Generated hideous O'Caml equivalent.
(* This file was automatically generated by
   Opium. Copyright 2008 K.D.P.Ross *)
Constructor ‘Var’ declared with arity 1.
Constructor ‘Lam’ declared with arity 2.
Constructor ‘App’ declared with arity 2.
type exp = Var of (string) | Lam of (string * exp) | App of (exp * exp)
and env = ((string * exp) list)
let rec eval generated_1 generated_0 = (match (generated_1 , generated_0) with (g, ((Var (x)))) -> ((assoc x) g) | (g, ((App (e1, e2)))) -> (match ((eval g) e1) with (Lam (x, e)) -> (let rec v = ((eval g) e2) in ((eval ((x , v) :: g)) e)) |-> (failwith "invalid application.")) | (g, e) -> e)
and showExp generated_2 = (match (generated_2) with (((Var (x)))) -> x | (((Lam (x, e)))) -> ((( +++ ) "(lambda ") ((( +++ ) x) ((( +++ ) " . ") ((( +++ ) (showExp e)) ")")))) | (((App (e1, e2)))) -> ((( +++ ) "(") ((( +++ ) (showExp e1)) ((( +++ ) (showExp e2)) ")")))) ;;
let generated_3 : (exp -> string) = showExp ;;
let generated_4 : (env -> (exp -> exp)) = eval ;;

More Information

Well, there's really no more information available for the time being, sorry! Please check back soon, though, or e-mail me if you have specific questions.

back

This page was generated by WebGen on KarmicPhoenix on Sun Nov 15 19:42:28 EST 2009.