I am new to Haskell and I played with Arrows. I would like to write a tool that can programmatically “parse” the previously created Arrow. As a potential application, imagine a function that takes an arrow and returns a directed graph that represents all concatenations, partitions, branches, etc.
For example, (f && g) →> h gives something like
Initially, I thought I could do this using pattern matching, as described below (adapted from the haskell.org Arrow tutorial), but that didn't work.
module Main(main) where import Control.Arrow import Control.Category import Prelude hiding (id, (.)) newtype SimpleFunc ab = SimpleFunc {runF :: (a -> b)} instance Arrow SimpleFunc where arr f = SimpleFunc f first (SimpleFunc f) = SimpleFunc (mapFst f) where mapFst g (a,b) = (ga, b) second (SimpleFunc f) = SimpleFunc (mapSnd f) where mapSnd g (a,b) = (a, gb) instance Category SimpleFunc where (SimpleFunc g) . (SimpleFunc f) = SimpleFunc (g . f) id = arr id f,g :: SimpleFunc Int Int f = arr (\x -> x - 5) g = arr (\x -> 3*x + 1) h1 :: SimpleFunc Int Int h1 = f >>> g h2 :: SimpleFunc Int (Int, Int) h2 = f &&& g
All my attempts to do this by defining my own types (for example, a parameterized type that includes child types) also failed.
Is there a way to “push apart” the arrow components after creating it?
source share