Last active
June 17, 2019 14:04
-
-
Save luochen1990/bc556d0fc6a1355e5d1bd27a81114870 to your computer and use it in GitHub Desktop.
demo: specify `HasCallStack` separately for different instance of same typeclass
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 InstanceSigs #-} | |
| import GHC.Stack | |
| class Next v where | |
| next :: HasCallStack => v -> v | |
| instance Next Bool where | |
| next :: Bool -> Bool | |
| next x = if x < maxBound then not x else undefined | |
| instance Next Int where | |
| next :: HasCallStack => Int -> Int | |
| next x = if x < maxBound then x + 1 else undefined | |
| main :: IO () | |
| main = do | |
| --print (next maxBound :: Bool) | |
| print (next maxBound :: Int) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment