[ANN] TypeL 0.1 -- extension of Common Lisp with strong typing
From: Ivan Boldyrev (boldyrev+nospam_at_cgitftp.uiggm.nsc.ru)
Date: 03/26/04
- Next message: Karl A. Krueger: "Re: CMUCL for Windows - how much $$$ ?"
- Previous message: Bob Coyne: "Re: CLM and CMUCL setup"
- Next in thread: Carl Shapiro: "Re: [ANN] TypeL 0.1 -- extension of Common Lisp with strong typing"
- Reply: Carl Shapiro: "Re: [ANN] TypeL 0.1 -- extension of Common Lisp with strong typing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 27 Mar 2004 03:47:48 +0600
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
TypeL is Common Lisp sublanguage with strong typing and type
inference a-la ML.
It is first version of TypeL, and it is very primitive. These
features are implemented:
1. Polymorphic type inference.
2. Curring.
3. TypeL is Lisp-1.
4. Arithmetic, boolean and list operations.
Features that will be implemented in feature releases:
1. Algebraic types and pattern matching.
2. Detailed error reporting.
3. Code optimization based on types.
TypeL is licensed under terms of LLGPL.
You can download TypeL from <http://lispnik.newmail.ru/typel>.
Examples:
======================================================================
(common-lisp:in-package "COMMON-LISP-USER")
;;; Expression inside typel:typel is type-checked.
(defun test (a b)
(declare (type integer a b))
(typel:typel ((a integer) (b integer))
(typel:+ a b)))
(test 1 2)
;;; => 3
(in-package "TYPEL-USER")
;;; Lists
;;; MAPCAR: ('TYPE31 -> 'TYPE28) -> (:LIST 'TYPE31) -> (:LIST 'TYPE28)
(deftypel ((mapcar fun list)
(if (equal nil list)
nil
(cons (fun (first list))
(mapcar fun (rest list))))))
;;; Curring: (+ 2) has type INTEGER -> INTEGER, because
;;; + has type INTEGER -> INTEGER -> INTEGER.
(typel ()
(mapcar (+ 2) (cons 1 (cons 2 nil))))
;;; => (3 4)
;;; Lambda expression. Don't use #' for lambdas.
(typel ()
(mapcar (lambda (x) (cons x nil)) (cons 1 (cons 2 nil))))
;;; => ((1) (2))
;;; This example demonstrates LETREC and curring
;;; FACT: INTEGER -> INTEGER
(deftypel
(fact ((letrec (((fact-acc acc n)
(if (0? n)
acc
(fact-acc (* acc n) (- n 1)))))
(fact-acc 1)))))
;;; Floating point math
;;; EXPONENTA: FLOAT -> INTEGER -> FLOAT
(deftypel
((exponenta x n)
(letrec (((exp-acc e p fact i)
(if (= i n)
e
(let ((new-fact (* fact i)))
(exp-acc (+. e (/. (*. p x) (int-to-float new-fact)))
(*. p x)
new-fact
(+ i 1))))))
(exp-acc 1.0 1.0 1 1))))
;;; Usage
(typel ()
(exponenta 1.0 100))
;;; => 2.7182818284590455d0
(typel ()
(exponenta 2.0 100))
;;; => 7.389056098930649d0
;;; Do not try to call EXPONENTA directly:
;;; (exponenta 2.0 100) ; <- will fail
;;; TypeL is Lisp-1.
;;; COMPOSE: (INTEGER -> INTEGER) -> (INTEGER -> INTEGER) -> INTEGER -> INTEGER
;;; ADD5: INTEGER -> INTEGER
(deftypel
((compose f g x)
(g (f x))))
((add5 n)
((compose (+ 2) (+ 3)) n)))
(typel () (add5 10))
;;; => 15
======================================================================
- --
Ivan Boldyrev
Today is the first day of the rest of your life.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.3.5 (GNU/Linux)
iQEVAwUBQGSlBg4ALcwzZFpVAQI2CAf+KvvIldXFTUlv5iIy0OErOK5nL2qE+ZWR
sCh1GXdr2pyWHo7yZRBn6ggh4xGcSVhkcAM/GsQfNJfgTcE8/W1LZRD6lMoRqkF3
FpU0rvNKU0dxWRxWgI3adtjpIX9yFNqOV38ocoS4SmZ+NhoAM0lPUccvE4BDyILV
zmWY8hNXYL++MlXsYIv8YflH4dhvwOEu33Towk7Y36v62YOnhBhIhMxVMUwEbj4m
eJaEmy8w4kHzALODuQr6nJFUZIH/EcZjcN/uIHx2oHOFi7Q07LZjANaNhAl2CtqG
iLKOnJdbV8rU2M+zVrGXK9Vr8Pa5bCq+xu/Myii6ykmWZi2M30iKEQ==
=042b
-----END PGP SIGNATURE-----
- Next message: Karl A. Krueger: "Re: CMUCL for Windows - how much $$$ ?"
- Previous message: Bob Coyne: "Re: CLM and CMUCL setup"
- Next in thread: Carl Shapiro: "Re: [ANN] TypeL 0.1 -- extension of Common Lisp with strong typing"
- Reply: Carl Shapiro: "Re: [ANN] TypeL 0.1 -- extension of Common Lisp with strong typing"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]