UNB/ CS/ David Bremner/ teaching/ cs3613/ racket/ plai-typed-demo
;; Follow  the instructions onhttp://www.cs.unb.ca/~bremner/teaching/cs3613/racket-setup/
;;   
;; from the course schedule page, then put
;;   #lang plai-typed
;; at the top of the definitions window and click run.

Welcome to DrRacket, version 6.7
Language: plai-typed; memory limit: 128 megabytes.
> 5
- number
5
> (+ 5 6)
- number
11
> (lambda (x) x)
- ('_a -> '_a)
#
> (lambda ([x : number]) x)
- (number -> number)
#

;; Use "Details" in "Choose Language" to select "Constructor" printing

> (lambda ([x : number]) x)
- (number -> number)
(lambda (a1) ...)
> ((lambda ([x : number]) x)  10)
- number
10
> (define f (lambda ([x : number]) x))
> f
- (number -> number)
f
> (values 1 2)
- (number * number)
'#(1 2)
> (values false "apple")
- (boolean * string)
'#(#f "apple")
> (lambda ([x : (number * number)]) x)
- ((number * number) -> (number * number))
(lambda (a1) ...)
> (lambda ([x : (number * number)]) (local
                                        [(define-values (a b) x)]
                                      (+ a b)))
- ((number * number) -> number)
(lambda (a1) ...)
> (lambda (x y) (+ x y))
- (number number -> number)
(lambda (a1 a2) ...)
> (list 1 2 3)
- (listof number)
'(1 2 3)
> (list 1 true)
typecheck failed: number vs boolean in:
  true
  true
  1
  (list 1 true)
> empty
- (listof 'a)
empty
> (cons 1 empty)
- (listof number)
'(1)
> (cons "apple" empty)
- (listof string)
'("apple")
> (define x 5)
> x
- number
5
> (local [(define y 17)]
    y)
- number
17
> y
y: free variable while typechecking in: y

;; Add to defnition window:
(define-type T
  [i (int : number)]
  [b (t-or-f : boolean)])

> (i 10)
- T
(i 10)
> (b false)
- T
(b false)

(define-type Maybe
  [nothing]
  [something (i : number)])

> (nothing)
- Maybe
(nothing)
> (something 10)
- Maybe
(something 10)

> (define x : number 5)
> x
- number
5
> (define len : ((listof number) -> number)
    (lambda (l)
      (cond
        [(empty? l) 0]
        [(cons? l) (+ 1 (len (rest l)))])))
> len
- ((listof number) -> number)
len
> (define len
    (lambda ([l : (listof number)]) : number
      (cond
        [(empty? l) 0]
        [(cons? l) (+ 1 (len (rest l)))])))
> len
- ((listof number) -> number)
len