Generalise the Result type
authorIustin Pop <iustin@google.com>
Sun, 7 Oct 2012 19:52:11 +0000 (21:52 +0200)
committerIustin Pop <iustin@google.com>
Wed, 17 Oct 2012 16:53:50 +0000 (18:53 +0200)
commit93be1ceda8962c3e1d39f78baeb522e54f7db6f7
tree9e194e80e48b5a003c32ea22e64028f76fcd8ae6
parent659d769de5459d709c7d6da4f585058e1a35db40
Generalise the Result type

Currently, our error monad—Result—has a plain string error type. This
is not good, as we don't have structured errors, we can't pass back
proper error information to Python code, etc.

To solve this, we generalise this type as 'GenericResult a', and make
Result an alias to 'GenericResult String' for compatibility with the
old code. New error hierarchies will be introduced as different
types. Furthermore, we generalise our helper functions too, so that
they can work on any 'GeneralInstance a' type, not only Result.

There are two small drawbacks to this generalisation. First, a Monad
instance requires (at least for the way we use it) a 'fail :: String
-> m a' instance, so we need to be able to build an 'a' value from a
string; therefore, we can implement the Monad instance only for a
newly-introduced typeclass, 'FromString', which requires the needed
conversion function. Second, due to the fact that 'String' is a type
alias (for [Char]) instead of an actual type, we need to enable the
FlexibleInstances language pragma; as far as I know, this has no
significant drawbacks.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
htest/Test/Ganeti/BasicTypes.hs
htest/Test/Ganeti/JSON.hs
htest/Test/Ganeti/TestCommon.hs
htools/Ganeti/BasicTypes.hs