This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type AccountKind = Simple | Valuable | MostValuable | |
type CustomerStatus = | |
| Unregistered | |
| Registered of AccountKind * Years:int | |
let accountFactor kind = | |
match kind with | |
| Simple -> 0.9m | |
| Valuable -> 0.7m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let accountFactor = function | |
| `Simple -> 0.9 | |
| `Valuable -> 0.7 | |
| `MostValuable -> 0.5 | |
let loyaltyFactor years = | |
1.0 -. float(min years 5) /. 100.0 | |
let applyDiscount price = function | |
| `Unregistered -> price |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D[_, _] := 0 | |
D[x_, x_] := 1 | |
D[f_ + g_, x_] := D[f, x] + D[g, x] | |
D[f_ - g_, x_] := D[f, x] - D[g, x] | |
D[f_ g_, x_] := f D[g, x] + g D[f, x] | |
D[f_ / g_, x_] := f D[1/g, x] + 1/g D[f, x] | |
D[f_^g_, x_] := f^(g - 1) (g D[f, x] + f Log[f] D[g, x]) | |
D[Log[f_], x_] := D[f, x] / f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 + x_ := x | |
x_ + 0 := x | |
f_ + (g_ + h_) := f + g + h | |
0 x_ := 0 | |
x_ 0 := 0 | |
1 x_ := x | |
x_ 1 := x | |
f_ (g_ h_) := f g h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Term = | |
| Var of int | |
| Pair of Term * Term | |
| Int of int | |
let (|Find|_|) s k = Map.tryFind k s | |
let rec walk (s: Map<_,_>) = function | |
| Var(Find s t) -> walk s t | |
| t -> t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let d x = function | |
| <:expr< $y$ >> when x=y -> <:expr< 1 >> | |
| <:expr< $f$ + $g$ >> -> <:expr< $d f x$ + $d g x$ >> | |
| <:expr< $f$ * $g$ >> -> <:expr< $f$ * $d g x$ + $g$ * $d f x$ >> | |
| _ -> <:expr< 0 >> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
D(x, y) -> 0 | |
D(x, x) -> 1 | |
D(f+g, x) -> D(f, x) + D(g, x) | |
D(f*g, x) -> f*D(g, x) + g*D(f, x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (|Float|_|) s = | |
let mutable x = 0.0 | |
if System.Double.TryParse(s, &x) then Some x else None | |
let binop f x y stack = | |
let z = f x y | |
printfn "%A" z | |
z::stack | |
let rec loop stack = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (|Float|_|) s = | |
let mutable x = 0.0 | |
if System.Double.TryParse(s, &x) then Some x else None | |
let rec (|Parse|) = function | |
| Float x::t -> <@ x @>, t | |
| "+"::Parse(x, Parse(y, t)) -> <@ %x + %y @>, t | |
| "*"::Parse(x, Parse(y, t)) -> <@ %x * %y @>, t | |
let (Parse(f, _)) = stdin.ReadToEnd().Split '\n' |> List.ofSeq |> List.rev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let (|Int|_|) s = | |
let mutable x = 0 | |
if System.Int32.TryParse(s, &x) then Some x else None | |
LLVM.NativeLibrary.LLVMDLL.Load() | |
LLVM.Target.InitializeNative() | |
let context = LLVM.Context.Global | |
let i32 = LLVM.IntegerType.GetInt32 context |