[Haskell-cafe] Building "production stable" software in Haskell
Hugh Perkins
hughperkins at gmail.com
Mon Sep 17 23:52:00 EDT 2007
Just out of curiosity, how could one do something like a factory, so
that by default a library uses, say, Data.Map, but by making a simple
assignment we can switch the library to use a different
implementation?
(This is alluded to above, but not explicitly stated. I guess it's
too easy, but someone has to ask the newbie questions :-D )
I guess we would need to have some sort of "init" function that
returns a state containing our various factories. The user could
update the factories with their own factories if they choose. The
state would need to be passed into each function call to the library
(!) ?
Or maybe one should store the state in a monad, and run everything
inside a monad?
Another newbie question, not entirely unrelated, but not entirely related ;-) :
- it seems that it is possible to run code inside multiple monads,
using transformers
- but it seems that there's no concept of "nesting"? ie, our code has
to explicitly know that it's going to be running inside exactly 2
monads (for example)
- or else, why does XmlToolbox, have 4 implementations for every
function, eg one using IO monad, one without IO monad, and two more
combinations involving a second monad?
>From http://www.haskell.org/haskellwiki/HXT:
"In HXT there are four types instanciated with these classes for pure
list arrows, list arrows with a state, list arrows with IO and list
arrows with a state and IO.
newtype LA a b = LA { runLA :: (a -> [b]) }
newtype SLA s a b = SLA { runSLA :: (s -> a -> (s, [b])) }
newtype IOLA a b = IOLA { runIOLA :: (a -> IO [b]) }
newtype IOSLA s a b = IOSLA { runIOSLA :: (s -> a -> IO (s, [b])) }"
More information about the Haskell-Cafe
mailing list