2026-08-25
Version.hs
-- write this: a record type named Version with fields major, minor, patch
-- (all Int, in that order), deriving Eq, Ord, and Show, so that comparing
-- two Versions compares major first, then minor, then patch
Version型を、カスタムのOrdインスタンスを書かずにderivingだけで、majorを最優先に、同じならminor、それも同じならpatchで比較されるように定義してください。
Reference
data Version = Version { major :: Int, minor :: Int, patch :: Int }
deriving (Eq, Ord, Show)
レコードに対してderiveされたOrdは、フィールドを宣言した順に左から辞書式に比較します。major、minor、patchの順でフィールドを書けば、それがそのままセマンティックバージョニングの比較順序になり、compareを自分で書く必要がありません。これは参考実装であり、唯一の正解ではありません。