Last active
March 17, 2018 21:30
-
-
Save sjoerdvisscher/050ceb08b6fcb68cda64d5b5eac7e235 to your computer and use it in GitHub Desktop.
Zeros implemented with one-liner
This file contains 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 DeriveAnyClass, DerivingStrategies, DefaultSignatures, TypeApplications, FlexibleContexts, DeriveGeneric #-} | |
import GHC.Generics | |
import Generics.OneLiner (nullaryOp, ADTRecord, Constraints) | |
class Zeros z where | |
zero :: z | |
default zero :: (ADTRecord z, Constraints z Zeros) => z | |
zero = nullaryOp @Zeros zero | |
{-# INLINE zero #-} | |
data B1 = B1 Int | |
deriving stock (Show, Read, Eq, Ord, Generic) | |
deriving anyclass (Zeros) | |
instance Zeros Int where zero = 0 | |
test :: B1 | |
test = zero |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment