on master help sign in
color example
commit8bc81d472549bb86a76ff91b76dfa7f291939cdf authorConal Elliott <conal@conal.net> dateSun 11 Sep 2016, 12:06 (10 years ago) parent1c5d55a
1 file changed+12−13
examples/Generic.hs+12−13
examples/Generic.hs+12−13
@@ -2,25 +2,24 @@
22import Data.MemoTrie
33import GHC.Generics (Generic)
44
5−data Color
6− = RGB Int Int Int
7− | NamedColor String
8− deriving (Generic)
5+data Color = RGB Int Int Int
6+ | NamedColor String
7+ deriving (Generic)
98
109instance HasTrie Color where
11− newtype (Color :->: b) = ColorTrie { unColorTrie :: Reg Color :->: b }
12− trie = trieGeneric ColorTrie
13− untrie = untrieGeneric unColorTrie
14− enumerate = enumerateGeneric unColorTrie
10+ newtype (Color :->: b) = ColorTrie { unColorTrie :: Reg Color :->: b }
11+ trie = trieGeneric ColorTrie
12+ untrie = untrieGeneric unColorTrie
13+ enumerate = enumerateGeneric unColorTrie
1514
1615runColor (RGB r g b) = r + g + b
1716runColor (NamedColor s) = length [1..10e7]
1817
1918runColorMemoized = memo runColor
2019
21−main = do
22− putStrLn "first call (should take a few seconds): "
23− print$ runColorMemoized (NamedColor "")
24− putStrLn "cached call (should be instantaneous): "
25− print$ runColorMemoized (NamedColor "")
20+main =
21+ do putStrLn "first call (should take a few seconds): "
22+ print$ runColorMemoized (NamedColor "")
23+ putStrLn "cached call (should be instantaneous): "
24+ print$ runColorMemoized (NamedColor "")
2625