From b8ccd25b6917a720c0b68479c976f18bc324922d Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 22 Apr 2023 19:46:04 +0200 Subject: Add Nat to initial ghci environment for lols --- bwrap-files/workdir/initdefs.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bwrap-files/workdir/initdefs.hs (limited to 'bwrap-files/workdir') diff --git a/bwrap-files/workdir/initdefs.hs b/bwrap-files/workdir/initdefs.hs new file mode 100644 index 0000000..7083fe0 --- /dev/null +++ b/bwrap-files/workdir/initdefs.hs @@ -0,0 +1,19 @@ +:{ +data Nat = Z | S Nat deriving (Show, Eq, Ord) + +instance Num Nat where + Z + n = n + S m + n = S (m + n) + Z * _ = Z + S m * n = n + m * n + negate _ = error "negate on Nat" + abs = id + signum Z = Z + signum _ = 1 + fromInteger n + | n < 0 = error "fromInteger to Nat on negative number" + | otherwise = + let go 0 = Z + go m = S (go (m-1)) + in go n +:} -- cgit v1.2.3-70-g09d2