Comonads are the categorical dual of monads.
extract s
extend g s
/ (=>>) s g
static member Extract (s: 'Comonad<'T>) : 'T
static member (=>>) (s: 'Comonad<'T>, f: 'Comonad<'T> -> 'U) : 'Comonad<'U>
static member Duplicate (x : 'Comonad<'T>) : 'Comonad<'Comonad<'T>>
extend extract = id
extract << extend f = f
extend f << extend g = extend (f << extend g)
- Monad: Comonads are the categorical dual of monads.
From .Net/F#
Async<'T>
Lazy<'T>
Id<'T>
('W * 'T)
struct ('W * 'T)
'Monoid -> 'T
ValueTask<'T>
From F#+
Suggest another concrete implementation
open FSharpPlus
open FSharpPlus.Data
// A non-empty list
let lst = {Head = 1; Tail = [2;3;4;5]}
// Get the head
let elem1 = extract lst
// Get ALL tails
let tails = duplicate lst
// This should return the original list
let lst' = extend extract lst
let ct1 = duplicate [1;2;3;4] // val it : List<List<int>> = [[1; 2; 3; 4]; [2; 3; 4]; [3; 4]; [4]]
let ct2 = duplicate ("a", 10) // val it : string * (string * int) = ("a", ("a", 10))
let ct3 = duplicate (fun (x:string) -> System.Int32.Parse x)
let r80100 = ct3 "80" "100"
let ct1' = extend id [1;2;3;4]
let ct2' = extend id ("a", 10)
let ct3' = extend id (fun (x:string) -> System.Int32.Parse x)
let ct1'' = (=>>) [1;2;3;4] id
let ct2'' = (=>>) ("a", 10) id
let ct3'' = (=>>) (fun (x:string) -> System.Int32.Parse x) id
val id: x: 'T -> 'T
namespace FSharpPlus
namespace FSharpPlus.Data
val lst: NonEmptyList<int>
val elem1: int
val extract: x: 'Comonad<'T> -> 'T (requires member Extract)
<summary>
Extracts a value from a comonadic context.
</summary>
<category index="17">Comonads</category>
val tails: NonEmptyList<NonEmptyList<int>>
val duplicate: x: 'Comonad<'T> -> 'Comonad<'Comonad<'T>> (requires member Duplicate)
<summary>
Duplicates a comonadic context.
</summary>
<category index="17">Comonads</category>
val lst': NonEmptyList<int>
val extend: g: ('Comonad<'T> -> 'U) -> s: 'Comonad<'T> -> 'Comonad<'U> (requires member (=>>))
<summary> Extends a local context-dependent computation to a global computation. </summary>
<category index="17">Comonads</category>
val ct1: int list list
val ct2: string * (string * int)
val ct3: (string -> string -> int)
val x: string
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
namespace System
[<Struct>]
type Int32 =
member CompareTo: value: int -> int + 1 overload
member Equals: obj: int -> bool + 1 overload
member GetHashCode: unit -> int
member GetTypeCode: unit -> TypeCode
member ToString: unit -> string + 3 overloads
member TryFormat: destination: Span<char> * charsWritten: byref<int> * ?format: ReadOnlySpan<char> * ?provider: IFormatProvider -> bool
static member Parse: s: ReadOnlySpan<char> * ?style: NumberStyles * ?provider: IFormatProvider -> int + 4 overloads
static member TryParse: s: ReadOnlySpan<char> * style: NumberStyles * provider: IFormatProvider * result: byref<int> -> bool + 3 overloads
static val MaxValue: int
static val MinValue: int
<summary>Represents a 32-bit signed integer.</summary>
System.Int32.Parse(s: string) : int
System.Int32.Parse(s: string, provider: System.IFormatProvider) : int
System.Int32.Parse(s: string, style: System.Globalization.NumberStyles) : int
System.Int32.Parse(s: string, style: System.Globalization.NumberStyles, provider: System.IFormatProvider) : int
System.Int32.Parse(s: System.ReadOnlySpan<char>, ?style: System.Globalization.NumberStyles, ?provider: System.IFormatProvider) : int
val r80100: int
val ct1': int list list
val ct2': string * (string * int)
val ct3': (string -> string -> int)
val ct1'': int list list
val ct2'': string * (string * int)
val ct3'': (string -> string -> int)