Powerset.hs 1.08 KB
Newer Older
Hans-Peter Deifel's avatar
Hans-Peter Deifel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}

module Data.Functors.Powerset where

import           Data.Vector (Vector)
import qualified Data.Vector as V
import qualified Data.Yaml as Yaml

import           Data.RefinementInterface
import qualified Data.MorphismEncoding as Encoding

data Powerset = Powerset
  deriving (Show)

instance RefinementInterface Powerset where
  type Label Powerset = ()
  type Weight Powerset = (Int, Int)
  type H1 Powerset = Bool
  type H3 Powerset = (Bool, Bool, Bool)

  parse _ = Yaml.withArray "Morphisms" $ \arr -> do
    succsessors <- V.imapM parseNode arr

    let structure = V.map (not . V.null . snd) succsessors
        edges = V.concatMap (\(from, succs) -> fmap (from,(),) succs) succsessors

    return $ Encoding.new structure edges

    where
      parseNode :: Int -> Yaml.Value -> Yaml.Parser (Int, Vector Int)
      parseNode nodeIdx value = (nodeIdx,) <$> Yaml.parseJSON value

powerset :: RefinableFunctor
powerset = RefinableFunctor
  { name = "Powerset"
  , parseArguments = NoArguments Powerset
  }