Skip to content

Northeastern University Type Comments to typed/racket

License

Notifications You must be signed in to change notification settings

falfiya/neut2tr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

neut2tr

Northeastern University Type Comments to typed/racket

This is a best-effort translator for Northeastern University Type Comments. It supports templates, generic declarations, aliases, annotations, sum types, and functions.

Install

Download a compiled binary from the releases tab. Alternatively, compile it from source:

go build .

Usage

neut2tr filename.rkt
   Converts NEU Type Comments to typed/racket and prints the result to stdout

neut2tr filename.rkt output.rkt
neut2tr filename.rkt -o output.rkt
neut2tr filename.rkt --out output.rkt
   Converts NEU Type Comments to typed/racket and writes to output.rkt

Example NEU Type Comments & Translation

Enum

; A TrafficLightColor is one of:
; - "Red"
; - "Yellow"
; - "Green"
(define-type TrafficLightColor (U "Red" "Yellow" "Green"))
; A CustomTruthy is one of:
; - #t
; - 1
; - "true"
(define-type CustomTruthy (U #t 1 "true"))

Union

; A StringOrZero is one of
; - String
; - 0
(define-type StringOrZero (U String 0))
; A [Listof X] is one of:
; - '()
; - (cons X [Listof X])
(define-type (Listof X) (U '() (cons X [Listof X])))
; A [Maybe X] is one of:
; - X
; - #f
(define-type (Maybe X) (U X #f))

Function

; display-clock : Minute -> Image
(: display-clock (-> Minute Image))
; generate-next : [Listof Real] -> [String -> Real]
(: generate-next (-> [Listof Real] (-> String Real)))
; map : {X Y} [X -> Y] [Listof X] -> [Listof Y]
(: map (All (X Y) (-> (-> X Y) [Listof X] [Listof Y])))
; foldr : {X Y} [X Y -> Y] Y [Listof X] -> Y
(: foldr (All (X Y) (-> (-> X Y Y) Y [Listof X] Y)))