Skip to content

Instantly share code, notes, and snippets.

@cronin101
Last active December 23, 2015 17:29
Show Gist options
  • Select an option

  • Save cronin101/6668695 to your computer and use it in GitHub Desktop.

Select an option

Save cronin101/6668695 to your computer and use it in GitHub Desktop.
Any example of how not to complete a first-year Haskell lab.
-- Informatics 1 - Functional Programming
-- Lab Week Exercise
--
-- Week 2 - due: Friday, Oct. 1, 5pm
--
-- Insert your name and matriculation number here:
-- Name: Willip Fodler
-- Nr. : 01
import Test.QuickCheck
import Control.Monad
-- Exercise 3:
double :: Int -> Int
double = join (+)
square :: Int -> Int
square = join (*)
-- Exercise 4:
isTriple :: Int -> Int -> Int -> Bool
isTriple = flip flip square . ((( . ) . (==)) . ) . ( . square) . (+) . square
-- Exercise 5:
leg1 :: Int -> Int -> Int
leg1 = ( . square ) . (-) . square
leg2 :: Int -> Int -> Int
leg2 = (*) . (2 *)
hyp :: Int -> Int -> Int
hyp = ( . square ) . (+) . square
-- Exercise 6:
prop_triple :: Int -> Int -> Bool
prop_triple = ap ( ap . ap (ap . (isTriple . ) . leg1) leg2) hyp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment