Ticket #3100: Foo2.hs

File Foo2.hs, 1.8 KB (added by mightybyte, 6 years ago)

A case that works, and some more information

Line 
1{-# OPTIONS -fglasgow-exts #-}
2{-# LANGUAGE TemplateHaskell , FlexibleInstances,
3             FlexibleContexts,
4             UndecidableInstances, OverlappingInstances,
5             MultiParamTypeClasses, GeneralizedNewtypeDeriving #-}
6
7import Data.Generics hiding ((:+:))
8import qualified Data.Map as Map
9import Data.Map (Map)
10import Data.Set (Set)
11import Data.Word
12import GHC.Unit
13import HAppS.Data
14import HAppS.Data.IxSet
15
16type PrimaryKey = Word64
17
18data Pair a = Pair a a
19
20data KeyedEntry a = KeyedEntry {
21  entryId :: PrimaryKey,
22  keLogEntry :: a
23} deriving (Read,Show,Ord,Eq,Typeable,Data)
24
25data LogEntry a = LogEntry {
26  logItem     :: a,
27  logComments :: String,
28  logUser     :: String
29} deriving (Read,Show,Ord,Eq,Typeable,Data)
30
31type TestEntry g = (Show g) => KeyedEntry (LogEntry (Pair g))
32
33-- This works
34$(inferIxSet "TestDB" ''KeyedEntry 'noCalcs [''PrimaryKey, ''String])
35
36-- This doesn't
37-- $(inferIxSet "TestDB" ''TestEntry 'noCalcs [''PrimaryKey, ''String])
38
39-- The code generated by template haskell for the working call to
40-- inferIxSet looks something like this (as shown by -ddump-splices):
41
42--instance Indexable (KeyedEntry a) () where
43--    empty = IxSet [Ix (Map.empty :: Map PrimaryKey (Set (KeyedEntry a))),
44--                   Ix (Map.empty :: Map String (Set (KeyedEntry a)))]
45--    calcs = noCalcs
46--type TestDB a = IxSet (KeyedEntry a)
47
48
49-- This next block does not work.  But GHC does not panic, it gives
50-- this error:
51--  Illegal polymorphic or qualified type: TestEntry a
52--  In the instance declaration for `Indexable (TestEntry a) ()'
53
54--instance Indexable (TestEntry a) () where
55--    empty = IxSet [Ix (Map.empty :: Map PrimaryKey (Set (TestEntry a))),
56--                   Ix (Map.empty :: Map String (Set (TestEntry a)))]
57--    calcs = noCalcs
58--type TestDB a = IxSet (TestEntry a)