0.2.2 • Published 11 years ago

deftypes v0.2.2

Weekly downloads
1
License
-
Repository
-
Last release
11 years ago

Deftypes

This is type annotaion DSL library.

Install

npm install deftypes

HOW TO USE

{def, struct, T} = require 'deftypes'

Point = struct { x: Number, y: Number}
p1 = def Point, {x: 1, y:2} #=> {x: 1, y:2}
# p2 = def Point, {x: 1, z:2} #=> type error

# function
f1 = def T.Func([Number, Number], String), (m, n) -> "#{m}, #{n}"
f1(1,2) #=> "1, 2"

# f1("",2) #=> error
get_distance = def T.Func([Point, Point], Number), (m, n) ->
  return Math.sqrt( Math.pow(m.x - n.x, 2) + Math.pow(m.y - n.y, 2))
get_distance({x:0, y:0},{x:3, y:4}) #=> 5

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

TODO

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

Caution

This is alpha version so I will change APIs.

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.0.0

11 years ago