Project Inquiry

Implement Prelude.fst and Prelude.snd

Challenge
{-# LANGUAGE NoImplicitPrelude #-}

module Main where

import           Prelude hiding (fst, snd)

main :: IO ()
main = putStrLn $ if test then "SUCCESS" else "FAILURE"

test :: Bool
test = and [ fst ("foo", 42) == "foo"
           , snd (42, "foo") == "foo"
           ]

-- TODO: This program doesn't compile. Define the missing function(s) incl. type signatures!
Solution
{-# LANGUAGE NoImplicitPrelude #-}

module Main where

import           Prelude hiding (fst, snd)

main :: IO ()
main = putStrLn $ if test then "SUCCESS" else "FAILURE"

test :: Bool
test = and [ fst ("foo", 42) == "foo"
           , snd (42, "foo") == "foo"
           ]

-- DONE
fst :: (a, b) -> a
fst (a, _) = a

snd :: (a, b) -> b
snd (_, b) = b