But I think that comonad is not famous.
This site describe the Store Comonad.
I write this Store Comonad in F#.
type Store<'b, 'a> = ('b -> 'a) * 'b
let Store v b : Store<'b, 'a> = (v, b)
let extract ((v, b) : Store<'b, 'a>) = v b
let fmap (f : 'a -> 'c) ((v, b) : Store<'b, 'a>) = Store (f << v) b let duplicate ((v, b) : Store<'b, 'a>) = Store (Store v) b
let extend (f : Store<'b, 'a> -> 'c) (x : Store<'b, 'a>) = fmap f (duplicate x)
No comments:
Post a Comment