[Haskell-cafe] FP design

Tim Docker timd at macquarie.com.au
Wed Nov 7 21:21:08 EST 2007

levi.stephen wrote:
> My concern (which may be inexperience ;) ) is with the monads here
> though. What if I hadn't seen that the IO monad (or any other Monad)
> was going to be necessary in the type signatures?

You'd have some refactoring to do :-) But actually, it's not possible
to create an interface that works this way without using some monad,
as the interface relies on side-effects. A pure interface would have
to look something like:

data ObjectStore = ObjectStore {
    save :: Object -> (ID,ObjectStore),
    retrieve :: ID -> Maybe Object,
    retrieveByName :: Maybe Object

(ie the save method would have to return a new object store).

Instead of using IO, you could have parameterised the store over the

data ObjectStore m = ObjectStore {
    save :: Object -> m ID,
    retrieve :: ID -> m (Maybe Object),
    retrieveByName :: String -> m (Maybe Object)

but given your planned use, this may well be over-abstraction.


More information about the Haskell-Cafe mailing list