Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static type system #48

Open
egisatoshi opened this issue Mar 6, 2014 · 1 comment
Open

Static type system #48

egisatoshi opened this issue Mar 6, 2014 · 1 comment
Labels
feature Feature ideas
Milestone

Comments

@egisatoshi
Copy link
Member

Egison version 4.0.0 will have static type system.

@egisatoshi egisatoshi added this to the 4.0.0 milestone Mar 6, 2014
@egisatoshi egisatoshi changed the title Static typing system Static type system Jul 14, 2014
@egisatoshi
Copy link
Member Author

Type System

Egison has static type system from version 4.

Type Declarations

Types are declarared as follow.

(define $map : (($A / $B) {A} / {B})
  (lambda [$fn $xs]
    (match xs (list something)
      {[<nil> {}]
       [<cons $x $rs> {(fn x) @(map fn rs)}]})))

Type Classes

We can use type classes as follow.
We don't support multi-parameter type classes.

(type $Ordering {<Less> <Equal> <Greater>})

(define $ordering : (Matcher Ordering)
  (algebraic-data-matcher
    {<less> <equal> <greater>}))

(class $Ord $A :: Eq
  {[$lt? : (A A / Bool)]}
  {[$lte? : (A A / Bool) (lambda [$x $y] (or (lt? x y) (eq? x y)))]
   [$gte? : (A A / Bool) (lt? $2 $1)]
   [$gt? : (A A / Bool) (lte? $2 $1)]
   [$compare : (A A / Ordering)
    (lambda [$m $n]
      (if (lt? m n)
        <Less>
        (if (eq? m n)
          <Equal>
          <Greater>)))]})

(instance Integer Ord {[$lt? lt-integer?]})

@momohatt momohatt modified the milestones: 4.0.0, 5.0.0 Nov 21, 2019
@momohatt momohatt modified the milestones: 5.0.0, 4.0.0 Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature ideas
Projects
None yet
Development

No branches or pull requests

2 participants