flower is a purely functional language with strong static typing.
flower provides following primitive data types
-
Int0 1 42 0x4f 0b0100 0o77 -
Float1.0 1.0e-19 0.001 6.022e+23 -
Booltrue : Bool false : Bool -
Char'a' 'x'
Additionally there are three type constructors given (all specified on every type - e.g. of kind *):
-
Maybe Awhich introduces possible lack of result -
Stream Awhich specifies lazy data stream -
Pair A B- a cartesian product or a 2-tuple
-
Intsum : Int -> Int -> Int sub : Int -> Int -> Int mul : Int -> Int -> Int quot : Int -> Int -> Maybe Int mod : Int -> Int -> Maybe Int neg : Int -> Int eq : Int -> Int -> Bool leq : Int -> Int -> Bool float : Int -> Float -
Floatsumf : Float -> Float -> Float subf : Float -> Float -> Float mulf : Float -> Float -> Float divf : Float -> Float -> Maybe Float negf : Float -> Float eqf : Float -> Float -> Bool leqf : Float -> Float -> Bool floor : Float -> Int ceil : Float -> Int -
Booland : Bool -> Bool -> Bool not : Bool -> Bool -
Charupper : Char -> Char lower : Char -> Char
Data constructors for composed types:
-
Maybe Afor A : * some : A -> Maybe A for A : * none : Maybe A -
Stream Afor A : * cons : A -> Stream A -> Stream A for A : * nil : Stream A -
Pair A Bfor A : *, B : * pair : A -> B -> Pair A B
And following selectors/modifiers:
-
Maybe Afor A : *, B : * maybe : (A -> B) -> B -> Maybe A -> B -
Stream Afor A : * head : Stream A -> Maybe A for A : * tail : Stream A -> Maybe (Stream A) for A : *, B : * stream : (A -> Stream A -> B) -> B -> Stream A -> B -
Pair A Bfor A : *, B : * fst : Pair A B -> A for A : *, B : * snd : Pair A B -> B
# End of line comment
(# Delimited comment #)
-
Not much of that (at the time being), but the following are equal:
cons 'A' (cons 'S' (cons 'D' nil)) "ASD"
for A : *, B : *, C : *
let compose : (B -> C) -> (A -> B) -> (A -> C) =
fun g f x ->
g (f x)
end
for A : *, B : *, C : *
let compose : (B -> C) -> (A -> B) -> (A -> C) =
fun f g a -> f (g a) end
for E : *, R : *
let foldLeft : (R -> E -> R) -> R -> Stream E -> R =
fun f acc ->
stream
(compose (foldLeft f) (f acc))
acc
end
Using the loop keyword (which refers to the inner most lambda):
for E : *, R : *
let foldLeft : (R -> E -> R) -> R -> Stream E -> R =
fun f ->
fun acc ->
stream
(compose loop (f acc))
acc
end
end
# Examples of concat, gt or filter implementations
# can be found in `stdlib.fl`
let qSort : Stream Int -> Stream Int =
stream
fun h t ->
concat
(qSort (filter (leq h) t))
(cons h (qSort (filter (gt h) t)))
end
nil