Skip to content

Instantly share code, notes, and snippets.

@Odomontois
Forked from ovechkin-dm/stepik.hs
Created March 19, 2018 13:36
Show Gist options
  • Save Odomontois/8f8b4e720d09fbec94a6fce01ada1178 to your computer and use it in GitHub Desktop.
Save Odomontois/8f8b4e720d09fbec94a6fce01ada1178 to your computer and use it in GitHub Desktop.
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Stepik () where
class (Enum a, Bounded a, Eq a) => SafeEnum a where
ssucc :: a -> a
ssucc x | x == maxBound = minBound
| otherwise = succ x
spred :: a -> a
spred x | x == minBound = maxBound
| otherwise = pred x
newtype SEnum a = SEnum{ getSEnum :: a} deriving (Enum, Bounded, Eq)
instance (Enum a, Bounded a, Eq a) => SafeEnum (SEnum a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment