シリーズ: haskell
haskell
31 行
· 更新日 2026-02-03
GPACalculator.hs
haskell/GPACalculator.hs
module GPACalculator
( Grade(..)
, Mark
, markToGrade
, markToGradeSafe
) where
data Grade
= Fail -- 0–49
| Pass -- 50–59
| Credit -- 60–69
| Distinction -- 70–79
| HighDistinction -- 80–100
deriving (Show, Eq, Ord, Enum, Bounded)
type Mark = Int
markToGrade :: Mark -> Grade
markToGrade m
| m < 0 || m > 100 = error "markToGrade: mark must be between 0 and 100"
| m >= 80 = HighDistinction
| m >= 70 = Distinction
| m >= 60 = Credit
| m >= 50 = Pass
| otherwise = Fail
-- Safe wrapper that never throws; out-of-range marks yield Nothing
markToGradeSafe :: Mark -> Maybe Grade
markToGradeSafe m
| m < 0 || m > 100 = Nothing
| otherwise = Just (markToGrade m)
関連記事
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).
記事を読む →