Skip to content

Instantly share code, notes, and snippets.

@Solonarv
Last active October 28, 2018 21:20
Show Gist options
  • Save Solonarv/bb1920e617d0eb7baa9ff7c56fcb52a3 to your computer and use it in GitHub Desktop.
Save Solonarv/bb1920e617d0eb7baa9ff7c56fcb52a3 to your computer and use it in GitHub Desktop.
{-# LANGUAGE DerivingStrategies, LambdaCase #-}
module Bijection (type Bijection, swap) where
import Data.Semigroup
import Data.Monoid
newtype Bijection a = Bijection { appBijection :: a -> a }
deriving (Semigroup, Monoid) via (Endo a)
swap :: Eq a => a -> a -> NatBijection
swap p q = Bijection $ \case
x | x == p -> q
| x == q -> p
| otherwise -> x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment