A collection of Haskell exercises focused on functional programming fundamentals, covering topics such as guards, pattern matching, monads, lambda expressions, and stateful computation.
- GHC (Glasgow Haskell Compiler)
1/
├── e1.hs Strict maximum of three integers
├── e2.hs Date validation with leap year handling
├── e3.hs Subway fare calculator with tiered discounts
├── e4.hs Change calculator using the State monad
├── e5.hs Oblong and triangular number checks via lambdas
├── e6.hs Integer concatenation through type casting
└── e7.hs Next-day date computation
Returns the largest of three positive integers only if it is unique (strict maximum). Returns -1 if no strict maximum exists. Implemented without logical operators.
Validates a date given as day, month, and year. Handles month-specific day limits and leap years using guards.
Computes the total monthly subway cost using a tiered discount system based on the number of trips:
| Trips | Discount |
|---|---|
| 1 - 20 | None |
| 21 - 30 | 20% |
| 31 - 40 | 30% |
| 40+ | 40% |
Uses Maybe to signal when no discount applies.
Determines the minimum number of bills to return as change for a purchase. Uses Control.Monad.State and Data.IntMap.Strict to track bill denominations ($5000, $1000, $500, $200, $100, $50, $10).
Lambda-based checks for:
- Oblong numbers: products of two consecutive naturals (e.g. 6 = 2 * 3).
- Triangular numbers: sums of consecutive naturals starting from 1 (e.g. 10 = 1+2+3+4).
Concatenates two positive integers by converting them to strings, joining, and reading back (e.g. 1234 and 567 becomes 1234567).
Computes the day following a given date. Handles month boundaries, year transitions, and leap years. Includes custom date parsing and format validation.
Compile and run any exercise with GHC:
ghc -o e1 1/e1.hs && ./e1Or interpret directly with runhaskell:
runhaskell 1/e1.hs- Guards and pattern matching
Maybefor optional resultsStatemonad for stateful computationIntMapfor efficient key-value storage- Lambda expressions
IOmonad for user interaction- Type casting with
read/show Text.Printffor formatted output