I am trying to use gdiff 1.1, the general diff library for Haskell, to get the difference between two objects that contain a list. However, I can’t get it to work, and I think it’s because I don’t know how to determine the instance for . Here is the code that I still have: Type FooFamily[FooEnvVar]
module Main where
import Data.Generic.Diff
data Foo = Foo { fooEnv :: [FooEnvVar] }
deriving (Show, Eq)
data FooStr = FooStr String
deriving (Show, Eq, Ord)
data FooEnvVar = FooEnvVar { fooEnvName :: FooStr }
deriving (Show, Eq, Ord)
data FooFamily :: * -> * -> * where
FooF :: FooFamily Foo (Cons [FooEnvVar] Nil)
FooStrF :: FooFamily FooStr (Cons String Nil)
instance Family FooFamily where
decEq FooF FooF = Just (Refl, Refl)
decEq FooStrF FooStrF = Just (Refl, Refl)
decEq _ _ = Nothing
fields FooF (Foo fe) = Just (CCons fe CNil)
fields FooStrF (FooStr str) = Just (CCons str CNil)
apply FooF (CCons fe CNil) = Foo fe
apply FooStrF (CCons str CNil) = FooStr str
string FooF = "FooF"
string FooStrF = "FooStrF"
instance Type FooFamily Foo where
constructors = [Concr FooF]
instance Type FooFamily [FooEnvVar] where
constructors = [] -- what should I put here?
main :: IO ()
main =
putStrLn $ show ((diff a b) :: EditScript FooFamily Foo Foo)
where
a = Foo [FooEnvVar (FooStr "hello"), FooEnvVar (FooStr "world")]
b = Foo [FooEnvVar (FooStr "hi"), FooEnvVar (FooStr "world")]
This code compiles without warning in GHC 8.0.1 with the option -Wall. When I run this code, I would like it to show the differences between aand b, but instead it shows this output:
test_gdiff: Incorrect Family or Type instance.
CallStack (from HasCallStack):
error, called at src/Data/Generic/Diff.hs:313:22 in gdiff-1.1-KTbM5AUQcBxD5ewDUGZ4O3:Data.Generic.Diff
In case it matters, I use the Haskell2010 language with these extensions: GADT, LambdaCase, MultiParamTypeClasses, OverloadedStrings, FlexibleInstances.
?