Reduce genSignals to a single line using Traversable.
[matthijs/master-project/cλash.git] / Flatten.hs
index cd515859f0879755d9d7f6e704bfb241271d9fbc..c8b95b4d92dab4854de0a618febf3296b6ba0750 100644 (file)
@@ -7,6 +7,7 @@ import qualified Name
 import qualified Maybe
 import qualified DataCon
 import qualified CoreUtils
+import qualified Data.Traversable as Traversable
 import Control.Applicative
 import Outputable ( showSDoc, ppr )
 import qualified Control.Monad.State as State
@@ -27,23 +28,10 @@ genSignals ::
   Type.Type
   -> FlattenState (SignalMap UnnamedSignal)
 
-genSignals ty = do
-  typeMapToUseMap tymap
-  where
-    -- First generate a map with the right structure containing the types
-    tymap = mkHsValueMap ty
-
-typeMapToUseMap ::
-  HsValueMap Type.Type
-  -> FlattenState (SignalMap UnnamedSignal)
-
-typeMapToUseMap (Single ty) = do
-  id <- genSignalId ty
-  return $ Single id
-
-typeMapToUseMap (Tuple tymaps) = do
-  usemaps <- State.mapM typeMapToUseMap tymaps
-  return $ Tuple usemaps
+genSignals ty =
+  -- First generate a map with the right structure containing the types, and
+  -- generate signals for each of them.
+  Traversable.mapM (\ty -> genSignalId SigInternal ty) (mkHsValueMap ty)
 
 -- | Flatten a haskell function
 flattenFunction ::