5 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: 
[<AutoOpen>]
module Either
type Either<'a, 'b> = Choice<'a, 'b>

module Either =
    let left = Either.Choice1Of2
    let right = Either.Choice2Of2
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

from Either

--------------------
module Either

--------------------
type Either<'a,'b> = Choice<'a,'b>

Full name: Either.Either<_,_>
type Either<'a,'b> = Choice<'a,'b>

Full name: Either.Either<_,_>
Multiple items
type Choice<'T1,'T2> =
  | Choice1Of2 of 'T1
  | Choice2Of2 of 'T2

Full name: Microsoft.FSharp.Core.Choice<_,_>

--------------------
type Choice<'T1,'T2,'T3> =
  | Choice1Of3 of 'T1
  | Choice2Of3 of 'T2
  | Choice3Of3 of 'T3

Full name: Microsoft.FSharp.Core.Choice<_,_,_>

--------------------
type Choice<'T1,'T2,'T3,'T4> =
  | Choice1Of4 of 'T1
  | Choice2Of4 of 'T2
  | Choice3Of4 of 'T3
  | Choice4Of4 of 'T4

Full name: Microsoft.FSharp.Core.Choice<_,_,_,_>

--------------------
type Choice<'T1,'T2,'T3,'T4,'T5> =
  | Choice1Of5 of 'T1
  | Choice2Of5 of 'T2
  | Choice3Of5 of 'T3
  | Choice4Of5 of 'T4
  | Choice5Of5 of 'T5

Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_>

--------------------
type Choice<'T1,'T2,'T3,'T4,'T5,'T6> =
  | Choice1Of6 of 'T1
  | Choice2Of6 of 'T2
  | Choice3Of6 of 'T3
  | Choice4Of6 of 'T4
  | Choice5Of6 of 'T5
  | Choice6Of6 of 'T6

Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_,_>

--------------------
type Choice<'T1,'T2,'T3,'T4,'T5,'T6,'T7> =
  | Choice1Of7 of 'T1
  | Choice2Of7 of 'T2
  | Choice3Of7 of 'T3
  | Choice4Of7 of 'T4
  | Choice5Of7 of 'T5
  | Choice6Of7 of 'T6
  | Choice7Of7 of 'T7

Full name: Microsoft.FSharp.Core.Choice<_,_,_,_,_,_,_>
Multiple items
module Either

from Either

--------------------
type Either<'a,'b> = Choice<'a,'b>

Full name: Either.Either<_,_>
val left : arg0:'a -> Choice<'a,'b>

Full name: Either.Either.left
union case Choice.Choice1Of2: 'T1 -> Choice<'T1,'T2>
val right : arg0:'a -> Choice<'b,'a>

Full name: Either.Either.right
union case Choice.Choice2Of2: 'T2 -> Choice<'T1,'T2>
Next Version Raw view Test code New version

More information

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