Demonstrate use of First Class Functions
parent
f675578f29
commit
f79f7822c7
@ -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
|
Loading…
Reference in New Issue