Jump to content

  • Log In with Google      Sign In   
  • Create Account






Sum types are now more powerful

Posted by ApochPiQ, 06 May 2012 · 657 views

Epoch
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!




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.

September 2014 »

S M T W T F S
 123456
78910111213
1415161718 19 20
21222324252627
282930    

Recent Entries

PARTNERS