packages feed

pointless-rewrite-0.0.1: src/Transform/Examples/Women.hs

-----------------------------------------------------------------------------
-- |
-- Module      :  Transform.Examples.Women
-- Copyright   :  (c) 2010 University of Minho
-- License     :  BSD3
--
-- Maintainer  :  hpacheco@di.uminho.pt
-- Stability   :  experimental
-- Portability :  non-portable
--
-- Pointless Rewrite:
-- automatic transformation system for point-free programs
-- 
-- Women lens example
--
-----------------------------------------------------------------------------

module Transform.Examples.Women where

import Data.Type
import Data.Lens
import Transform.Rewriting
import Transform.Rules.Lenses
import Transform.Rules.PF
import Transform.Rules.PF.Rec

import Generics.Pointless.Combinators
import Generics.Pointless.Functors
import Generics.Pointless.Lenses
import Generics.Pointless.Lenses.Examples.MapExamples hiding (women_opt)

instance Typeable Gender where
    typeof = Data "Gender" fctrof

men :: Pf (Lens [Person] Nat)
men = LENGTH_LNS _L .<< FILTER_LEFT_LNS .<< MAP_LNS (OUT_LNS .<< SND_LNS (PNT "woman" .= BANG))

women :: Pf (Lens [Person] Nat)
women = LENGTH_LNS _L .<< FILTER_RIGHT_LNS .<< MAP_LNS (OUT_LNS .<< SND_LNS (PNT "woman" .= BANG))

men_opt = reduceIO optimise_lns typeof men
women_opt = reduceIO optimise_lns typeof women

womenput = women_opt >>= reduceIO (many (once (top fzip_def ||| top functor_def))) typeof . putof typeof
womenput_opt = women_opt >>= reduceIO (optimise_pf >>> beautify_pf) typeof . putof typeof