Skip to main content
GameDev.net gamedev.net

PRO Tired of ads? Read GameDev.net ad-free and help keep the community independent with GameDev Pro — $3/month.

Types

Types

Daerax
Journal · · 2 min read
1,168 0
So my last question was a bit of a lead in question.

A long time ago I tried to make an RPG in C with classes. I got burned terribly, stopped programming for 2 years and so am now paranoid. I am still on a quest to make a game but since I am only one programmer, I first require a language with a certain level of expressivity. Inspired by Tim Sweenies paper I set about a requirement list. Including standard closures, currying, partial application, higher ordered functions, algebraic types, tuples etc, I require:

Eased writing of parallel and concurrent code (simple - use the .NET Task Parallel library and F# async blocks), polymorphic variants, Generalized Algebraic data Types or similar (I think both can be approximated with abstract types , matching on types, views,extensible matching - active patterns in F#. perhaps some metaprogramming), dependentish types (using phantoms), higher kinded polymoprphism (though I can think of few reasons to have it,was just to allow), proper monads (useful I suspect for AI and other gameplay type code). I am still using my F# Nemerle combo for a language near enough to haskell on .NET. I solved i think - to my satisfaction at least - the prior things and shall be blogging on them as time comes my way:

Number Parameterized types and basic statically checked type level computations:

Sometime ago I was able to use phantom types and nemerle's metaprogramming capabilites to define dependent types like behaviour with type level arithmetic. This extends the type system with a bit more power while allowing the code to not become too dense. The downside is the added syntax and extra annotations.
def z  = vec n //where the type of n is known at compile time and hence the size of z[Enforce n < 50 && m - n != 0]method(n : Natural , m : Natural, o : int, v : vec 5 )  dtype n + 50  {}/*<-- dtype types the method and also the parameters and adds the neceassary type variables. Writing method[a,b,c,d] (n : Natural[a], ...) is cumbersome.  All statically checked with phantoms.*/{}
More on this later.

The other thing amongst others (haskell like monads with similar sugared notation) Ive done is again simulating the notion of higher kinded polymorphism using phantom types. This will be the subject of my next post.

Discussion

Loading comments...