Last active
October 28, 2018 21:20
-
-
Save Solonarv/bb1920e617d0eb7baa9ff7c56fcb52a3 to your computer and use it in GitHub Desktop.
This file contains 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 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