Skip to content

Instantly share code, notes, and snippets.

@luochen1990
Last active June 17, 2019 14:04
Show Gist options
  • Select an option

  • Save luochen1990/bc556d0fc6a1355e5d1bd27a81114870 to your computer and use it in GitHub Desktop.

Select an option

Save luochen1990/bc556d0fc6a1355e5d1bd27a81114870 to your computer and use it in GitHub Desktop.
demo: specify `HasCallStack` separately for different instance of same typeclass
{-# 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