Created
November 27, 2019 08:21
-
-
Save chansey97/f2b1d0a04d1a5b025655aa869a274466 to your computer and use it in GitHub Desktop.
ctfp-14.3.6-wrong-solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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