Three toads and the spit of a badger

Published October 13, 2014
Advertisement
So Epoch has a couple of warts that I'm looking at smoothing out. One of them has to do with overloads that do type decomposition of algebraic sum types:

//// How things look today//type Optional : T | nothingTest : integer x{ print(cast(string, x))}Test : nothing{ print("Nothing")}entrypoint :{ Optional exists = 42 Optional doesntexist = nothing Test(exists) Test(doesntexist)}I'm thinking about modifying the parser so that overloads of a function can be chained together without repeating the function name, by just specifying the signature of an overload immediately after the body of the function, and following with the body of the overload:

//// How things look with implicit overloads//type Optional : T | nothingTest : integer x { print(cast(string, x)) } : nothing { print("Nothing") }entrypoint :{ Optional exists = 42 Optional doesntexist = nothing Test(exists) Test(doesntexist)}The last question I want to ask is what lambdas look like, and whether or not they can help compact this code even further. Here's one thought experiment:

//// Experiment with lambda syntax//type Optional : T | nothingentrypoint :{ Optional exists = 42 Optional doesntexist = nothing var f = lambda :(integer x) { print(cast(string, x)) } :(nothing) { print("Nothing") } f(exists) f(doesntexist)}I'm not totally sold on the lambda syntax yet. I do like the idea of allowing overloads of lambdas, specifically for the type decomposition thing. Or maybe type decomposition just really needs a first-class structure, like case:

//// Experimental case statement//type Optional : T | nothingTest : Optional in{ case(in) : integer x { print(cast(string, x)) } : nothing { print("Nothing") }}entrypoint :{ Optional exists = 42 Optional doesntexist = nothing Test(exists) Test(doesntexist)}
Previous Entry Watching syntax evolve
Next Entry Epoch Mailing List
1 likes 1 comments

Comments

Washu
Pattern matching is definitely important and making it a first class option of the language seems like it would be a good idea to me.
October 15, 2014 03:49 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement