5 people like it.
Like the snippet!
Haskell to F# (some operators)
Just toying around with making my F# code a little smaller with Haskell operators
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
|
(* The start of a Haskell Operator Module *)
(* Application opeator *)
let ($) a b = a b
(* List concat operator *)
let (++) a b = List.append a b
(* Raise-to-the-power operators *)
let (^) (a: int) (b: int) = [1..b] |> List.map(fun _ -> a) |> List.reduce((*))
let (^^) (a: int) (b: int) = [1..b] |> List.map(fun _ -> a) |> List.reduce((*))
(* Force evaluation (strictness flag) *)
let (!) (a: Lazy<'a>) = a.Force()
(* Wildcard *)
let otherwise = _
(* Usage *)
let concat = [1;2;3] ++ [4;5]
>> [1;2;3;4;5]
let application = (fun x -> x + 6) $ 6
>> 12
let r = 3 ^ 5
>> 243
let r2 = 3 ^^ 5
>> 243
let x = 10
let r3 = lazy (x + 10)
let final = ! r3
>> 20
|
val a : ('a -> 'b)
val b : 'a
val a : 'a list
val b : 'a list
Multiple items
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
val append : list1:'T list -> list2:'T list -> 'T list
Full name: Microsoft.FSharp.Collections.List.append
val a : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
val b : int
val map : mapping:('T -> 'U) -> list:'T list -> 'U list
Full name: Microsoft.FSharp.Collections.List.map
val reduce : reduction:('T -> 'T -> 'T) -> list:'T list -> 'T
Full name: Microsoft.FSharp.Collections.List.reduce
val a : Lazy<'a>
Multiple items
active recognizer Lazy: Lazy<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.( |Lazy| )
--------------------
type Lazy<'T> = System.Lazy<'T>
Full name: Microsoft.FSharp.Control.Lazy<_>
member System.Lazy.Force : unit -> 'T
val otherwise : 'a
Full name: Script.otherwise
val concat : int list
Full name: Script.concat
More information