Skip to content

Instantly share code, notes, and snippets.

@takoeight0821
Created June 5, 2015 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takoeight0821/8d8d7603667dc8a2cf5d to your computer and use it in GitHub Desktop.
Save takoeight0821/8d8d7603667dc8a2cf5d to your computer and use it in GitHub Desktop.
群 in Haskell
import Data.Monoid
class Group g where
gidentity :: g
gop :: g -> g -> g
ginverse :: g -> g
instance Num a => Group (Sum a) where
gidentity = Sum 0
(Sum x) `gop` (Sum y) = Sum (x + y)
ginverse (Sum a) = Sum (negate a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment