1. Nathan Howell
  2. z3-haskell

Commits

Nathan Howell  committed c44c412

Derive Foldable/Traversable for the Base.Result type

  • Participants
  • Parent commits a3a0da6
  • Branches default

Comments (0)

Files changed (2)

File Z3/Base.hs

View file
  • Ignore whitespace
 {-# LANGUAGE DeriveDataTypeable  #-}
+{-# LANGUAGE DeriveFoldable #-}
+{-# LANGUAGE DeriveTraversable #-}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE IncoherentInstances #-}
 import Z3.Lang.TY
 
 import Control.Applicative ( Applicative(..), (<$>) )
+import Data.Foldable ( Foldable )
 import Data.Int
 import Data.Ratio ( Ratio, numerator, denominator, (%) )
+import Data.Traversable ( Traversable )
 import Data.Typeable ( Typeable, typeOf )
 import Data.Word
 import Foreign hiding ( newForeignPtr, addForeignPtrFinalizer, toBool )
     = Sat a
     | Unsat
     | Undef
-    deriving (Eq, Ord, Read, Show)
+    deriving (Eq, Ord, Read, Show, Foldable, Traversable)
 
 instance Functor Result where
   fmap f (Sat x) = Sat $ f x

File Z3/Lang/Monad.hs

View file
  • Ignore whitespace
 
 import Control.Applicative ( Applicative )
 import Control.Monad.State
+import Data.Traversable ( traverse )
 
 ---------------------------------------------------------------------
 -- The Z3 Monad
 showModel = do
   c <- gets context
   mm <- getModel
-  case mm of
-    Base.Sat m -> liftZ3 . liftM Base.Sat $ Base.showModel c m
-    Base.Unsat -> return Base.Unsat
-    Base.Undef -> return Base.Undef
+  liftZ3 $ traverse (Base.showModel c) mm
 
 showContext :: Z3 String
 showContext = do