Skip to content
This repository has been archived by the owner on Aug 4, 2018. It is now read-only.

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
dmalikov committed Aug 18, 2012
1 parent 8bc4e27 commit 1843c9a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/ex1.hs
@@ -0,0 +1,27 @@
{-# LANGUAGE UnicodeSyntax #-}

import Control.Monad (replicateM)
import Data.Poset
import Data.Poset.Morphism

p Poset Int
p = fromPairsE [1..7] [(3,1),(3,2),(4,2),(5,3),(5,4),(6,1),(6,4),(7,5),(7,6)]

main IO ()
main =
mapM_ (print . toPerm) $ filter (nice p) $ generate (length $ elements p)

-- | Generate all possible Morphs over n-size set
--
generate Int [Morph Int]
generate n = map fromPerm $ replicateM n [1..n]

-- | Build Morph from permutation
--
fromPerm [Int] Morph Int
fromPerm = Morph . zip [1..]

-- | Show Morph as a permutation
--
toPerm Morph Int [Int]
toPerm (Morph m) = map snd m

0 comments on commit 1843c9a

Please sign in to comment.