Created
August 8, 2020 20:14
-
-
Save cronokirby/106bbba1ad8a82f34cab87020215cbcb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE RankNTypes #-} | |
| newtype Nat = Nat { unNat :: forall m. Monoid m => m -> m } | |
| instance Num Nat where | |
| Nat f + Nat g = Nat (\m -> f m <> g m) | |
| Nat f * Nat g = Nat (\m -> f (g m)) | |
| abs = id | |
| negate _ = error "negate @Nat" | |
| signum (Nat f) = if f [()] == [] then 0 else 1 | |
| fromInteger 0 = Nat (const mempty) | |
| fromInteger x = Nat (\m -> m <> unNat (fromInteger (x - 1)) m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment