系列: haskell
haskell
26 行
· 更新於 2026-02-03
exercise_1.hs
haskell/Week_6_Lab/exercise_1.hs
-- Define a compose function that evaluates the composition of two functions, given an input.
compose :: (b -> c) -> (a -> b) -> a -> c
compose f g x = f (g x)
-- Given functions
square :: Integer -> Integer
square x = x^2
inc :: Integer -> Integer
inc x = x + 1
-- Computes the function f(x) = (x+1)^2
incThenSquare :: Integer -> Integer
incThenSquare = compose square inc
-- Computes the function f(x) = x^2 + 1
squareThenInc :: Integer -> Integer
squareThenInc = compose inc square
-- Computes the function f(x) = x+2
add2 :: Integer -> Integer
add2 = compose inc inc
-- Computes the function f(x) = x^4 + 1
quadThenInc :: Integer -> Integer
quadThenInc = compose inc (compose square square)
相關文章
haskell
haskell
更新於 2026-02-03
Adding.hs
Adding.hs — haskell source code from the haskell learning materials (haskell/Adding.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
Area.hs
Area.hs — haskell source code from the haskell learning materials (haskell/Area.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
Chess.hs
Chess.hs — haskell source code from the haskell learning materials (haskell/Chess.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the haskell learning materials (haskell/ChessGraphics.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
Examples.hs
Examples.hs — haskell source code from the haskell learning materials (haskell/Examples.hs).
閱讀文章 →
haskell
haskell
更新於 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the haskell learning materials (haskell/Fibonacci.hs).
閱讀文章 →