Série: haskell
haskell
32 linhas
· Atualizado 2026-02-03
Nat.hs
haskell/Week9/Nat.hs
{-|
Module : Nat
Author : COMP1100 Team, Your name and UID here
Date :
Description : Deriving equality and order on Nat
-}
module Nat where
{-
Exercise 3A, 3B: Defining equality and ordering on Nat
Using the template given, define all the functions required for
`Nat` to be a member of `Eq` and `Ord`.
DO NOT USE "deriving Eq" or "deriving Ord".
You should define the instances of (==) and (<=) yourself.
-}
data Nat = Z | S Nat
deriving (Show)
instance Eq Nat where
Z == Z = True
(S n) == (S m) = n == m
_ == _ = False
instance Ord Nat where
Z <= _ = True
(S _) <= Z = False
(S n) <= (S m) = n <= m
Artigos relacionados
haskell
haskell
Atualizado 2026-02-03
Adding.hs
Adding.hs — haskell source code from the haskell learning materials (haskell/Adding.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
Area.hs
Area.hs — haskell source code from the haskell learning materials (haskell/Area.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
Chess.hs
Chess.hs — haskell source code from the haskell learning materials (haskell/Chess.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
ChessGraphics.hs
ChessGraphics.hs — haskell source code from the haskell learning materials (haskell/ChessGraphics.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
Examples.hs
Examples.hs — haskell source code from the haskell learning materials (haskell/Examples.hs).
Ler artigo →
haskell
haskell
Atualizado 2026-02-03
Fibonacci.hs
Fibonacci.hs — haskell source code from the haskell learning materials (haskell/Fibonacci.hs).
Ler artigo →