Skip to content

Commit d80a4ad

Browse files
committed
Update docs
1 parent 9844fcc commit d80a4ad

14 files changed

+185
-107
lines changed

docsrc/content/abstraction-alternative.fsx

+22-11
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Applicative Functors which also have a monoid structure.
1010
___
1111
Minimal complete definition
1212
---------------------------
13-
* ``return x``/``result x``
13+
* ``return x``   /   ``result x``
1414
* ``(<*>) f x``
1515
* ``empty``
16-
* ``append x y``/``(<|>) x y``
16+
* ``append x y`` &nbsp; / &nbsp; ``(<|>) x y``
1717
*)
1818
(**
19-
static member Return (x:'T) : 'Alternative<'T>
20-
static member (<*>) (f:'T->'U, x:Alternative<'T>) : Alternative<'U>
21-
static member get_Empty () :'Alternative
22-
static member (<|>) (x:'Alternative<'T>, y:'Alternative<'T>) :'Alternative<'T>
19+
static member Return (x: 'T) : 'Alternative<'T>
20+
static member (<*>) (f: 'T -> 'U, x: 'Alternative<'T>) : 'Alternative<'U>
21+
static member get_Empty () : 'Alternative
22+
static member (<|>) (x: 'Alternative<'T>, y: 'Alternative<'T>) : 'Alternative<'T>
2323
*)
2424
(**
2525
Note: ``return`` can't be used outside computation expressions, use ``result`` instead.
@@ -28,11 +28,14 @@ Other operations
2828
* ``mfilter``
2929
*)
3030
(**
31-
static member MFilter (x:seq<'Alternative>) :'Alternative
31+
static member MFilter (x: seq<'Alternative>) : 'Alternative
3232
*)
3333
(**
3434
* ``choice``
3535
*)
36+
(**
37+
static member inline Choice (source: 'Foldable<'Alt<'T>>) : 'Alt<'T>
38+
*)
3639
(**
3740
Rules
3841
-----
@@ -56,13 +59,16 @@ Concrete implementations
5659
From .Net/F#
5760
5861
- ``list<'T>``
59-
- ``option<'T>``
6062
- ``array<'T>``
6163
- ``seq<'T>``
64+
- ``option<'T>``
65+
- ``voption<'T>``
66+
- ``Result<'T, 'Monoid>``
67+
- ``Choice<'T, 'Monoid>``
6268
- ``'T -> 'Alternative``
63-
69+
6470
From F#+
65-
71+
6672
- [``ReaderT<'R, 'MonadPlus<'T>>``](type-readert.html)
6773
- [``WriterT<'MonadPlus<'T * 'Monoid>>``](type-writert.html)
6874
- [``StateT<'S,'MonadPlus<'T * 'S>>``](type-statet.html)
@@ -73,7 +79,12 @@ From F#+
7379
- [``Compose<'AlternativeF<'AlternativeG<'T>>>``](type-compose.html)
7480
- [``DList<'T>``](type-dlist.html)
7581
- [``ZipList<'S>``](type-ziplist.html)
76-
82+
- [``NonEmptySeq<'T>``](type-nonemptyseq.html) ``*``
83+
- [``Validation<'Error, 'T>``](type-validation.html) ``*``
84+
85+
``*`` Only ``<|>`` operation
86+
87+
7788
[Suggest another](https://github.com/fsprojects/FSharpPlus/issues/new) concrete implementation
7889
7990
Examples

docsrc/content/abstraction-applicative.fsx

+20-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ A functor with application, providing operations to embed pure expressions (``re
1010
___
1111
Minimal complete definition
1212
---------------------------
13-
* ``return x``/``result x``
13+
* ``return x`` &nbsp; / &nbsp; ``result x``
1414
* ``(<*>) f x``
1515
*)
1616
(**
17-
static member Return (x:'T) : 'Applicative<'T>
18-
static member (<*>) (f: 'Applicative<'T->'U>, x: 'Applicative<'T>) : 'Applicative<'U>
17+
static member Return (x: 'T) : 'Applicative<'T>
18+
static member (<*>) (f: 'Applicative<'T -> 'U>, x: 'Applicative<'T>) : 'Applicative<'U>
1919
*)
2020
(**
2121
Note: ``return`` can't be used outside computation expressions, use ``result`` instead.
@@ -27,7 +27,7 @@ Other operations
2727
* ``lift2``
2828
*)
2929
(**
30-
static member Lift2 (f: 'T1->'T2->'T, x1: 'Applicative<'T1>, x2: 'Applicative<'T2>) : 'Applicative<'T>
30+
static member Lift2 (f: 'T1 -> 'T2 -> 'T, x1: 'Applicative<'T1>, x2: 'Applicative<'T2>) : 'Applicative<'T>
3131
*)
3232
(**
3333
@@ -131,13 +131,13 @@ open FSharpPlus
131131
open FSharpPlus.Data
132132

133133
// Apply +4 to a list
134-
let lst5n6 = map ((+) 4) [ 1;2 ]
134+
let lst5n6 = map ((+) 4) [ 1; 2 ]
135135

136136
// Apply +4 to an array
137-
let arr5n6 = map ((+) 4) [|1;2|]
137+
let arr5n6 = map ((+) 4) [|1; 2|]
138138

139139
// I could have written this
140-
let arr5n6' = (+) <!> [|4|] <*> [|1;2|]
140+
let arr5n6' = (+) <!> [|4|] <*> [|1; 2|]
141141

142142
// Add two options
143143
let opt120 = (+) <!> Some 20 <*> tryParse "100"
@@ -198,7 +198,7 @@ open FSharpPlus.Math.Applicative
198198
let opt121' = Some 21 .+. tryParse "100"
199199
let optTrue = 30 >. tryParse "29"
200200
let optFalse = tryParse "30" .< 29
201-
let m1m2m3 = -.[1;2;3]
201+
let m1m2m3 = -.[1; 2; 3]
202202

203203

204204
// Using applicative computation expression
@@ -245,7 +245,17 @@ let person6 = applicative2 {
245245
// A Monad is automatically an Applicative
246246

247247
type MyList<'s> = MyList of 's seq with
248-
static member Return (x:'a) = MyList (Seq.singleton x)
248+
static member Return (x: 'a) = MyList (Seq.singleton x)
249249
static member (>>=) (MyList x: MyList<'T>, f) = MyList (Seq.collect (f >> (fun (MyList x) -> x)) x)
250250

251-
let mappedMyList : MyList<_> = (MyList [(+) 1;(+) 2;(+) 3]) <*> (MyList [1;2;3])
251+
let mappedMyList : MyList<_> = (MyList [(+) 1; (+) 2; (+) 3]) <*> (MyList [1; 2; 3])
252+
253+
254+
(**
255+
Recommended reading
256+
-------------------
257+
258+
- Highly recommended Matt Thornton's blog [Grokking Applicatives](https://dev.to/choc13/grokking-applicatives-44o1).
259+
It contains examples using F#+ and an explanation from scratch.
260+
261+
*)

docsrc/content/abstraction-bifoldable.fsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ From .Net/F#
7979
8080
- ``'T * 'U``
8181
- ``struct ('T * 'U)``
82-
- ``Result<'T,'U>``
83-
- ``Choice<'T,'U>``
82+
- ``Result<'T, 'U>``
83+
- ``Choice<'T, 'U>``
8484
8585
8686
From F#+
8787
88-
- [``Const<'C,'T>``](type-const.html)
89-
- [``Validation<'err,'a>``](type-validation.html)
88+
- [``Const<'C, 'T>``](type-const.html)
89+
- [``Validation<'Error, 'T>``](type-validation.html)
9090
9191
[Suggest another](https://github.com/fsprojects/FSharpPlus/issues/new) concrete implementation
9292

docsrc/content/abstraction-bifunctor.fsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ From .Net/F#
6868
6969
- ``'T1 * 'T2``
7070
- ``struct ('T1 * 'T2)``
71-
- ``Result<'T2,'T1>``
72-
- ``Choice<'T2,'T1>``
73-
- ``KeyValuePair<'T1,'T2>``
71+
- ``Result<'T2, 'T1>``
72+
- ``Choice<'T2, 'T1>``
73+
- ``KeyValuePair<'T1, 'T2>``
7474
7575
7676
From F#+
7777
78-
- [``Const<'C,'T>``](type-const.html)
79-
- [``Validation<'Error,'T>``](type-validation.html)
78+
- [``Const<'C, 'T>``](type-const.html)
79+
- [``Validation<'Error, 'T>``](type-validation.html)
8080
8181
[Suggest another](https://github.com/fsprojects/FSharpPlus/issues/new) concrete implementation
8282

docsrc/content/abstraction-bitraversable.fsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ From .Net/F#
5454
5555
- ``'T * 'U``
5656
- ``struct ('T * 'U)``
57-
- ``Result<'T,'U>``
58-
- ``Choice<'T,'U>``
57+
- ``Result<'T, 'U>``
58+
- ``Choice<'T, 'U>``
5959
6060
6161
From F#+
6262
63-
- [``Const<'C,'T>``](type-const.html)
64-
- [``Validation<'Error,'T>``](type-validation.html)
63+
- [``Const<'C, 'T>``](type-const.html)
64+
- [``Validation<'Error, 'T>``](type-validation.html)
6565
6666
6767
[Suggest another](https://github.com/fsprojects/FSharpPlus/issues/new) concrete implementation

docsrc/content/abstraction-category.fsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Concrete implementations
5555
5656
From .Net/F#
5757
58-
- ``'T->'U``
59-
- ``Func<'T,'U>``
58+
- ``'T -> 'U``
59+
- ``Func<'T, 'U>``
6060
6161
6262
From F#+

docsrc/content/abstraction-functor.fsx

+41-32
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ The Functor abstraction is used for types that can be mapped over.
1010
___
1111
Minimal complete definition
1212
---------------------------
13-
* ``map f x``/``(|>>) x f``/``(<<|) f x``/``(<!>) f x``
13+
* ``map f x`` &nbsp; / &nbsp; ``(|>>) x f`` &nbsp; / &nbsp; ``(<<|) f x`` &nbsp; / &nbsp; ``(<!>) f x``
1414
*)
1515
(**
16-
static member Map (x:'Functor<'T>, f:'T->'U) :'Functor<'U>
16+
static member Map (x: 'Functor<'T>, f: 'T -> 'U) : 'Functor<'U>
1717
*)
1818
(**
1919
Other operations
2020
----------------
2121
* ``unzip x``
2222
*)
2323
(**
24-
static member Unzip (x:Functor<'T * 'U>) :'Functor<'T> * 'Functor<'U>
24+
static member Unzip (x: 'Functor<'T * 'U>) : 'Functor<'T> * 'Functor<'U>
2525
*)
2626
(**
2727
Rules
@@ -54,49 +54,49 @@ From F#
5454
- ``Async<'T>``
5555
- ``Result<'T,'U>``
5656
- ``Choice<'T,'U>``
57-
- ``KeyValuePair<'Key,'T>``
57+
- ``KeyValuePair<'Key, 'T>``
5858
- ``Map<'Key,'T>``
5959
- ``'Monoid * 'T``
6060
- ``'struct ('Monoid * 'T)``
6161
- ``Task<'T>``
6262
- ``ValueTask<'T>``
6363
- ``'R->'T``
6464
- ``Expr<'T>``
65-
- ``Dictionary<'Key,'T>``
66-
- ``IDictionary<'Key,'T>``
67-
- ``IReadOnlyDictionary<'Key,'T>``
65+
- ``Dictionary<'Key, 'T>``
66+
- ``IDictionary<'Key,' T>``
67+
- ``IReadOnlyDictionary<'Key, 'T>``
6868
- ``ResizeArray<'T>``
6969
7070
From F#+
7171
72-
- [``Cont<'R,'T>``](type-cont.html)
73-
- [``ContT<'R,'T>``](type-contt.html)
74-
- [``Reader<'R,'T>``](type-reader.html)
75-
- [``ReaderT<'R,'Monad<'T>>``](type-readert.html)
76-
- [``Writer<'Monoid,'T>``](type-writer.html)
72+
- [``Cont<'R, 'T>``](type-cont.html)
73+
- [``ContT<'R, 'T>``](type-contt.html)
74+
- [``Reader<'R, 'T>``](type-reader.html)
75+
- [``ReaderT<'R, 'Monad<'T>>``](type-readert.html)
76+
- [``Writer<'Monoid, 'T>``](type-writer.html)
7777
- [``WriterT<'Monad<'T * 'Monoid>>``](type-writert.html)
78-
- [``State<'S,'T * 'S>``](type-state.html)
79-
- [``StateT<'S,'Monad<'T * 'S>>``](type-statet.html)
78+
- [``State<'S, 'T * 'S>``](type-state.html)
79+
- [``StateT<'S, 'Monad<'T * 'S>>``](type-statet.html)
8080
- [``OptionT<'Monad<option<'T>>``](type-optiont.html)
8181
- [``ValueOptionT<'Monad<voption<'T>>``](type-valueoptiont.html)
8282
- [``SeqT<'Monad<seq<'T>>``](type-seqt.html)
8383
- [``ListT<'Monad<list<'T>>``](type-listt.html)
84-
- [``ResultT<'Monad<Result<'T,'TError>>``](type-resultt.html)
85-
- [``ChoiceT<'Monad<Choice<'T,'TError>>``](type-choicet.html)
86-
- [``Free<'Functor<'T>,'T>``](type-free.html)
84+
- [``ResultT<'Monad<Result<'T, 'TError>>``](type-resultt.html)
85+
- [``ChoiceT<'Monad<Choice<'T, 'TError>>``](type-choicet.html)
86+
- [``Free<'Functor<'T>, 'T>``](type-free.html)
8787
- [``NonEmptyList<'T>``](type-nonempty.html)
8888
- [``NonEmptySet<'T>``](type-nonempty-set.html)
8989
- [``NonEmptyMap<'Key, 'T>``](type-nonempty-map.html)
90-
- [``Validation<'Error,'T>``](type-validation.html)
90+
- [``Validation<'Error, 'T>``](type-validation.html)
9191
- [``ZipList<'T>``](type-ziplist.html)
9292
- [``ParallelArray<'T>``](type-parallelarray.html)
93-
- [``Const<'C,'T>``](type-const.html)
93+
- [``Const<'C, 'T>``](type-const.html)
9494
- [``Compose<'AlternativeF<'AlternativeG<'T>>>``](type-compose.html)
9595
- [``DList<'T>``](type-dlist.html)
9696
- [``Kleisli<'T, 'Monad<'U>>``](type-kleisli.html)
97-
- [``Coproduct<'FunctorL<'T>,'FunctorR<'T>>``](type-coproduct.html)
98-
- [``Vector<'T,'Dimension>``](type-vector.html)
99-
- [``Matrix<'T,'Rows,'Columns>``](type-matrix.html)
97+
- [``Coproduct<'FunctorL<'T>, 'FunctorR<'T>>``](type-coproduct.html)
98+
- [``Vector<'T, 'Dimension>``](type-vector.html)
99+
- [``Matrix<'T, 'Rows, 'Columns>``](type-matrix.html)
100100
101101
Restricted:
102102
- ``string``
@@ -118,7 +118,7 @@ Examples
118118
open FSharpPlus
119119
open FSharpPlus.Math.Generic
120120

121-
let getLine = async { return System.Console.ReadLine() }
121+
let getLine = async { return System.Console.ReadLine () }
122122
let putStrLn x = async { printfn "%s" x}
123123
let print x = async { printfn "%A" x}
124124

@@ -141,8 +141,8 @@ let noValue = map minus3 None
141141
let lstTimes2 = map times2 [1;2;3;4]
142142
let fTimes2minus3 = map minus3 times2
143143
let res39 = fTimes2minus3 21G
144-
let getChars = map (fun (x:string) -> x.ToCharArray() |> Seq.toList ) action
145-
let quot7 = map ((+)2) <@ 5 @>
144+
let getChars = map (fun (x: string) -> x.ToCharArray () |> Seq.toList) action
145+
let quot7 = map ((+) 2) <@ 5 @>
146146

147147

148148
// try -> runIO getChars ;;
@@ -153,11 +153,11 @@ type Tree<'a> =
153153
| Leaf of 'a
154154
static member map f (t:Tree<'a> ) =
155155
match t with
156-
| Leaf x -> Leaf (f x)
157-
| Tree(x,t1,t2) -> Tree(f x, Tree.map f t1, Tree.map f t2)
156+
| Leaf x -> Leaf (f x)
157+
| Tree (x, t1, t2) -> Tree (f x, Tree.map f t1, Tree.map f t2)
158158

159159
// add instance for Functor class
160-
static member Map (x:Tree<_>, f) = Tree.map f x
160+
static member Map (x: Tree<_>, f) = Tree.map f x
161161

162162
let myTree = Tree(6, Tree(2, Leaf 1, Leaf 3), Leaf 9)
163163
let mappedTree = map fTimes2minus3 myTree
@@ -167,10 +167,10 @@ let mappedTree = map fTimes2minus3 myTree
167167
// An Applicative is automatically a Functor
168168

169169
type ZipList<'s> = ZipList of 's seq with
170-
static member Return (x:'a) = ZipList (Seq.initInfinite (konst x))
171-
static member (<*>) (ZipList (f:seq<'a->'b>), ZipList x) = ZipList (Seq.zip f x |> Seq.map (fun (f, x) -> f x)) : ZipList<'b>
170+
static member Return (x: 'a) = ZipList (Seq.initInfinite (konst x))
171+
static member (<*>) (ZipList (f :seq<'a->'b>), ZipList x) = ZipList (Seq.zip f x |> Seq.map (fun (f, x) -> f x)) : ZipList<'b>
172172

173-
let mappedZipList = map string (ZipList [1;2;3])
173+
let mappedZipList = map string (ZipList [1; 2; 3])
174174

175175

176176
// A Monad is automatically a Functor
@@ -179,4 +179,13 @@ type MyList<'s> = MyList of 's seq with
179179
static member Return (x:'a) = MyList x
180180
static member (>>=) (MyList x: MyList<'T>, f) = MyList (Seq.collect (f >> (fun (MyList x) -> x)) x)
181181

182-
let mappedMyList = map string (MyList [1;2;3])
182+
let mappedMyList = map string (MyList [1; 2; 3])
183+
184+
185+
(**
186+
Recommended reading
187+
-------------------
188+
189+
- Highly recommended Matt Thornton's blog [Grokking Functors](https://dev.to/choc13/grokking-functors-bla).
190+
It contains examples using F#+ and an explanation from scratch.
191+
*)

0 commit comments

Comments
 (0)