Lazy (call-by-need)
Pure
Static
Dynamic
Duck-typed
Functional
Object-oriented
| Language | Pure | Strict | Non-Strict (Lazy) |
|---|---|---|---|
| Haskell | Yes | No | Yes |
| ML | |||
| Erlang | |||
| Scheme | |||
| Java | |||
| C# | |||
| Scala | |||
| Ruby | |||
| F# | |||
| SQL | |||
| Regex |
Snippets and thoughts from a passionate software developer interested in all things DevOps, Continuous Delivery, Functional Programming, Distributed Systems. Also on Twitter as @mcallana.
| Language | Pure | Strict | Non-Strict (Lazy) |
|---|---|---|---|
| Haskell | Yes | No | Yes |
| ML | |||
| Erlang | |||
| Scheme | |||
| Java | |||
| C# | |||
| Scala | |||
| Ruby | |||
| F# | |||
| SQL | |||
| Regex |
# letp=10;;val p : int = 10
# letkx=(x,p,x+p);;val k : int -> int * int * int =
# kp;;- : int * int * int = 10, 10, 20
# letp=1000;;val p : int = 1000
# kp;;- : int * int * int = 1000, 10, 1010
http://caml.inria.fr/pub/docs/manual-ocaml/expr.html
Looping:while expr1 do expr2 done
for name = expr1 to expr2 do expr3 done
for name = expr1 downto expr2 do expr3 done
Exceptions: try ... with ... -> ...
Objects
Coercion (casting to superclass): subobject :> superclass
Message sending (calling method on object): object # method
Object duplication: Oo.copy
Recursive functions: rec
String concatenation: ^
Characters delimited by ` not ': `a`
http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora016.html#toc21
Tuples
Records
Sum Types
Constant Constructor: typesuit=Spades|Hearts|Diamonds|Clubs;;
Constructor with Args: typecard=Kingofsuit|Queenofsuit|Knightofsuit|Knaveofsuit|Minor_cardofsuit*int|Trumpofint|Joker;;
Recursive Types
Parameterised Types: type('a,'b)list2=
a1 >>= a2 = join (fmap a2 a1)
fmap _ Nothing = Nothing
fmap someFunction (Just a) = Just (someFunction a)
> fmap (+ 2) (Just 4)
Just 6
> fmap (+ 2) (Nothing)
Nothing
join Nothing = Nothing
join (Just Nothing) = Nothing
join (Just (Just x)) = Just x
(f x) means the same as (f $ x). However, $ has low, right-associative binding precedence, so it sometimes allows parentheses to be omitted; do expression.