Commit 79191100 authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Add Lift instances for Maybe and Either

parent 2eabf4ab
......@@ -202,6 +202,14 @@ instance Lift Bool where
lift True = return (ConE trueName)
lift False = return (ConE falseName)
instance Lift a => Lift (Maybe a) where
lift Nothing = return (ConE nothingName)
lift (Just x) = liftM (ConE justName `AppE`) (lift x)
instance (Lift a, Lift b) => Lift (Either a b) where
lift (Left x) = liftM (ConE leftName `AppE`) (lift x)
lift (Right y) = liftM (ConE rightName `AppE`) (lift y)
instance Lift a => Lift [a] where
lift xs = do { xs' <- mapM lift xs; return (ListE xs') }
......@@ -245,6 +253,14 @@ trueName, falseName :: Name
trueName = mkNameG DataName "base" "GHC.Base" "True"
falseName = mkNameG DataName "base" "GHC.Base" "False"
nothingName, justName :: Name
nothingName = mkNameG DataName "base" "Data.Maybe" "Nothing"
justName = mkNameG DataName "base" "Data.Maybe" "Just"
leftName, rightName :: Name
leftName = mkNameG DataName "base" "Data.Either" "Left"
rightName = mkNameG DataName "base" "Data.Either" "Right"
-- Names and uniques
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment