3 (* Copyright Jeremy Yallop 2007.
4 This file is free software, distributed under the MIT license.
5 See the file COPYING for details.
11 val map
: ('a
-> 'b
) -> 'a f
-> 'b f
14 module MonadFunctor
(M
: Monad
)
15 : Functor
with type 'a f
= 'a
M.m
20 let map f x
= x
>>= (fun x
-> return
(f x
))
24 module Functor_option
= MonadFunctor
(Monad.Monad_option
)
25 module Functor_list
= MonadFunctor
(Monad.Monad_list
)
27 module Functor_map
(O
: Map.OrderedType
)
28 : Functor
with type 'a f
= 'a
Map.Make
(O
).t
=
35 NB: Instances for mutable types (including
44 are deliberately omitted. Since sharing is detectable for values of
45 these types we have two distinct design choices:
47 1. Always create a new copy that shares no structure with the
50 2. Always mutate the original copy
52 Neither of these seems like the right thing to do, so instead we
53 simply don't handle mustable types at all.
55 (Lazy.t is another example: we'd like map to be total and side-effect
56 free, which is impossible to guarantee if we handle lazy.