deftypes

type annotation DSL

Deftypes

This is type annotaion DSL library.

npm install deftypes
{defstructT} = require 'deftypes'
 
Point = struct { x: Numbery: Number}
p1 = def Point{x: 1y:2} #=> {x: 1, y:2} 
# p2 = def Point, {x: 1, z:2} #=> type error 
 
# function 
f1 = def T.Func([NumberNumber]String)(m, n) -> "#{m}#{n}"
f1(1,2) #=> "1, 2" 
 
# f1("",2) #=> error 
get_distance = def T.Func([PointPoint]Number)(m, n) ->
  return Math.sqrt( Math.pow(m.- n.x2) + Math.pow(m.- n.y2))
get_distance({x:0y:0},{x:3y:4}) #=> 5 

when T.debug is false, typechecker does nothing, passing through def like transparent for avoiding performance down.

  • more DSL about funcion definition
  • transparent production mode
  • trait feature
  • browser build
  • struct inheritance
  • fix struct definition
  • separate type system from this repo

This is alpha version so I will change APIs.