Original Post
I'm developing a (impure) functional language at the moment, and I've been trying to decide on a syntax. This is what I've come up with so far (not terribly original, but that isn't necessarily a bad thing):
factorial :: Integer a => a -> a
let factorial
(x == 0) { 1 }
(x == 1) { 1 }
(x > 1) { x * (factorial (x - 1)) };;
fibonacci :: Integer a => a -> a
let fibonacci
(x == 0) { 1 }
(x == 1) { 1 }
(x > 1) { (fibonacci (x - 1)) + (fibonacci (x - 2)) };;
map :: Any a, Any b => (a -> b) -> [a] ->
let map
_ [] { [] }
f (x : xs) { (f x) : (map f xs) };;
reduce :: Any a => (a -> a -> a) -> [a] -> a
let reduce
f (x : []) { x }
f (x : xs) { (f x (reduce f xs)) };;
interface Vector {
length :: Void -> Float
normalize :: Void -> Vector
};;
class Vector3D implements Vector {
x, y, z :: Float, Float, Float
let length () {
x = sqrt (self.x + self.y + self.z)
};;
let normalize () {
instance Vector3D {
let x = self.x / (self.length)
let y = self.y / (self.length)
let z = self.z / (self.length)
}
}
};;
So, any comments and/or suggestions?