3 people like it.

Either in F#

Had to throw together a Haskell-style Either type in F# since Choice is a pain in the ass.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
[<AutoOpen>]
module Either

type Either<'a, 'b> =
    | Left of 'a
    | Right of 'b

type either<'a, 'b> =
    Either<'a, 'b> // lower-case alias like option

let isLeft = function
  | Left _ -> true
  | _      -> false

let isRight = function
  | Right _ -> true
  | _      -> false
Multiple items
type AutoOpenAttribute =
  inherit Attribute
  new : unit -> AutoOpenAttribute
  new : path:string -> AutoOpenAttribute
  member Path : string

Full name: Microsoft.FSharp.Core.AutoOpenAttribute

--------------------
new : unit -> AutoOpenAttribute
new : path:string -> AutoOpenAttribute
Multiple items
module Either

--------------------
type Either<'a,'b> =
  | Left of 'a
  | Right of 'b

Full name: Either.Either<_,_>
type Either<'a,'b> =
  | Left of 'a
  | Right of 'b

Full name: Either.Either<_,_>
union case Either.Left: 'a -> Either<'a,'b>
union case Either.Right: 'b -> Either<'a,'b>
type either<'a,'b> = Either<'a,'b>

Full name: Either.either<_,_>
val isLeft : _arg1:Either<'a,'b> -> bool

Full name: Either.isLeft
val isRight : _arg1:Either<'a,'b> -> bool

Full name: Either.isRight

More information

Link:http://fssnip.net/ji
Posted:4 years ago
Author:Bryan Edds
Tags: f# , either