Skip to content

Instantly share code, notes, and snippets.

@chansey97
Created November 27, 2019 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chansey97/f2b1d0a04d1a5b025655aa869a274466 to your computer and use it in GitHub Desktop.
Save chansey97/f2b1d0a04d1a5b025655aa869a274466 to your computer and use it in GitHub Desktop.
ctfp-14.3.6-wrong-solution
{-# LANGUAGE DeriveFunctor, TypeFamilies #-}
module Main where
data Pair a = Pair a a
deriving (Eq)
getFst :: Pair a -> a
getFst (Pair x1 _) = x1
getSnd :: Pair a -> a
getSnd (Pair _ x2) = x2
class Representable f where
type Rep f :: *
tabulate :: (Rep f -> x) -> f x
index :: f x -> Rep f -> x
instance Representable Pair where
type Rep Pair = ()
tabulate f = Pair (f ()) (f ()) -- fmap f Pair((),())
index (Pair x1 x2) = \u -> x1
-- index (tabulate f)
f :: () -> String
f x = "AAA"
tabulatef :: Pair String
tabulatef = tabulate f
indextabulatef :: () -> String
indextabulatef = index tabulatef
check1 = indextabulatef () == "AAA"
-- tabulate (index Pair x1 x2)
pair :: Pair String
pair = Pair "A" "B"
indexpair :: ()->String
indexpair = index pair
tabulateindexpair :: Pair String
tabulateindexpair = tabulate indexpair
check2 = tabulateindexpair == Pair "A" "B"
main = do
putStrLn "test"
putStrLn (show check1)
putStrLn (show check2)
putStrLn (show (getFst tabulateindexpair))
putStrLn (show (getSnd tabulateindexpair))
--GHCi, version 8.6.5
--test
--True
--False
--"A"
--"A"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment