Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Programming contest: Type checker.

Name: Anonymous 2011-11-03 8:09

Task: Write a type checker and inference engine for this small statically typed language (parser and evaluator optional. You may enter the AST directly in the source code, and you only need to ensure that invalid programs are failed and valid ones are passed).


; def: (def symbol arguments code), (def symbol code) or (def symbol)
; ∀: (∀ (variables) ((constraints)) code) returns code
; ∷: (∷ symbol type) returns symbol, type-annotated.
; →: (→ type1 type2 … returnType) returns type
; #+: primitive + of type (→ Int Int Int)

(def (∷ + (→ Int Int)) (x) x)
(def (∀ (χ) ((∷ + (→ Int . χ))) (∷ + (→ Int Int . χ)))
    (x y . r) (+ (#+ x y) . r)))

; (+ 1 1 1) → 3
; (+ 1 1 1 1) → 4
; ((+ 1) 1) → 2 (the language is curried)

; Interface example, assume an IO monad, String, write and sprintf:
(def (∷ Writeable (∀ (χ) ((∷ write (→ χ String (IO ())))) χ)))
(def (∷ fprintf (∀ (χ α) ((∷ Writeable χ) (∷ sprintf (→ ,@α String))) (→ χ ,@α (IO ()))))
    (a . b) (write a (sprintf . b))

Everything type annotation except the interface example should be able to be inferred. Feel free to improve the syntax of types that now use unquote-splicing as long as the semantics are the same.

The winner will be decided on the 1st of January. Criterions will be code size, elegance, helpfulness of error messages, and speed.

Name: Anonymous 2011-11-03 9:12

>>2
If you mean something like ML, then it's partly because SEXP has an easier AST for the purposes of this contest. Also, I think it will be a lot sexier with SRFI 49 and without type annotations.

>>4
Was there something you failed to understand?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List