Haskell/Solutions/Understanding arrows

      (>>>)

      Exercises
      What is the type of the combined arrow?

      The combined arrow has type a b d.

      ↑Jump back a section

      first

      Exercises
      What is the type of the first robot?

      first :: a b c -> a (b,d) (c,d)

      ↑Jump back a section

      second

      Exercises
      1. Write a function to swap two components of a tuple.
      2. Combine this helper function with the robots arr, (>>>) and first to implement the second robot
      swap :: (a,b) -> (b,a)
      swap (a,b) = (b,a)
      
      second :: (Arrow a) => a b c -> a (d,b) (d,c)
      second a = arr swap >>> first a >>> arr swap
      
      ↑Jump back a section

      (***)

      Exercises
      1. What is the type of the (***) robot?
      2. Given the (>>>), first and second robots, implement the (***) robot.
      (***) :: a b d -> a c e -> a (b,c) (d,e)
      
      f *** g = first f >>> second g
      
      ↑Jump back a section

      (&&&)

      Exercises
      1. Write a simple function to clone an input into a pair.
      2. Using your cloning function, as well as the robots arr, (>>>) and ***, implement the &&& robot
      3. Similarly, rewrite the following function without using &&&:
      addA f g = f &&& g >>> arr (\ (y, z) -> y + z)
      
      clone a = (a,a)
      
      f &&& g = arr clone >>> f *** g
      
      addA f g = arr clone >>> f *** g >>> arr (\(y,z) -> y + z)
      -- OR
      addA f g = arr clone >>> f *** g >>> arr (uncurry (+))
      
      ↑Jump back a section

      Arrow combinators (robots)

      Exercises
      1. Consider the charA parser from above. What would charA 'o' >>> charA 'n' >>> charA 'e' result in?
      2. Write a simplified version of that combined parser. That is: does it accept the empty string? What are its starting symbols? What is the dynamic parser for this?

      FIXME: No solutions.


      ↑Jump back a section
      Last modified on 23 April 2013, at 00:36