Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!






More steroids for Epoch's type system!

Posted by ApochPiQ, 28 April 2012 · 879 views

Epoch
This program now compiles and runs under the Epoch trunk:

//
// SUMTYPEFUNCTION.EPOCH
//
// Basic test of functions operating on sum types
//

type test : integer | string



sumfunc : integer param
{
    assert(param == 42)
}

sumfunc : string param
{
    assert(param == "bletch")
}


entrypoint :
{
    test foo = 42
    test bar = "bletch"

    sumfunc(foo)
    sumfunc(bar)

    print("Pass")
}


This paves the way for things like optional (nullable) types, and other coolness.

Typing is entirely static at the moment; if you initialize a sum type with type A, it will transparently convert the variable to type A during compilation, and the variable will always be of that type. Since the language already has overload support, decomposing a sum typed variable into its "real" type is trivial, as shown above.

The one missing feature is pass-through support (i.e. where I take a sum type and pass it through a function without inspecting it, which I can't do because I haven't settled on its type statically). I'll probably hack on that next.

For now, though, I'm pretty happy with how easy it was to get sum types working as well as they are. With the addition of a special "nothing" type and some generic-programming goodies, it should be possible to do pretty amazing stuff with the Epoch type system real soon now.


Woot.




So does Epoch get an asterisk next to its name in the record books?
Yes, but the asterisk leads to a footnote that says "kicks extra ass."

August 2015 »

S M T W T F S
      1
2345678
9101112131415
16171819202122
2324252627 28 29
3031     
PARTNERS