From f79f7822c76568655fe1ac896351547d7e20b92a Mon Sep 17 00:00:00 2001 From: Hammy Date: Sun, 4 Apr 2021 22:43:45 +0100 Subject: [PATCH] Demonstrate use of First Class Functions --- Unit 1/Lesson 4/firstClassFunctions.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Unit 1/Lesson 4/firstClassFunctions.hs diff --git a/Unit 1/Lesson 4/firstClassFunctions.hs b/Unit 1/Lesson 4/firstClassFunctions.hs new file mode 100644 index 0000000..f363d32 --- /dev/null +++ b/Unit 1/Lesson 4/firstClassFunctions.hs @@ -0,0 +1,19 @@ +inc :: Num a => a -> a +inc n = n + 1 +double :: Num a => a -> a +double n = n * 2 +square :: Num a => a -> a +square n = n ^ 2 + +isEven :: Integral p => (p -> p) -> p -> p +isEven myFunction x = if even x + then myFunction x + else x + + +ifEvenDouble :: Integral p => p -> p +ifEvenDouble x = isEven double x +ifEvenInc :: Integral p => p -> p +ifEvenInc x = isEven inc x +ifEvenSquare :: Integral p => p -> p +ifEvenSquare x = isEven square x \ No newline at end of file