• entries
    625
  • comments
    1446
  • views
    1007170

Sum types are now more powerful

Sign in to follow this  
ApochPiQ

803 views

I worked on the sum type implementation for a while, and finally got it up to the point where you can dynamically alter the type of data stored in a sum-typed variable. This is subtly different from dynamic typing; the possible types of the variable are bounded at compile time, and the compiler guarantees that you can always act on the data at run time regardless of what type it actually ends up being.

Bottom line, this test now works:

//
// SUMTYPESTRUCTURE.EPOCH
//
// Test of holding a sum-typed value in a structure member
//


type intorstring : integer | string

structure s :
intorstring alpha,
intorstring beta


operate : s param
{
check(param.alpha)
check(param.beta)
}


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

check : string param
{
assert(param == "test")
}


entrypoint :
{
s foo = 42, "test"
s bar = "test", 42
s baz = 42, 42
s quux = "test", "test"

operate(foo)
operate(bar)
operate(baz)
operate(quux)

print("Pass")
}



Next up I'm going to give a shot at implementing a dynamic list structure using this functionality. Once that works I'll probably start on templates/generics to get the compiler to the point where I can implement much more interesting stuff without repeating boilerplate code... things like containers, and so on.

Should be interesting!
Sign in to follow this  


1 Comment


Recommended Comments

Craziness. You're going to get us killed when the universe collapses because of your meddlings. =)
You're lucky we're no longer in the dark ages, or 'purist' programmers would strap you to a server and burn you alive.

Keep up the crazy stuff you are doing! I find it all very interesting.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now