5 people like it.

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: 
(* 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()
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

More information

Link:http://fssnip.net/b8
Posted:12 years ago
Author:Cameron Frederick
Tags: haskell , haskell operators