--TODO: add arrayOf for objects with @[] in them.

-- |Converts a type environment (presumably, a top-level type-environment)
-- to a list of 'InterfaceItem's.
toInterface :: Env
            -> [InterfaceItem]
toInterface env = map toExport (M.toList env) where
  toExport (v,t) = InterfaceExport v noPos
                                   (toContract' t)
  toContract' Nothing = error "Contracts.hs : export without type"
  toContract' (Just (type_, _, _)) = toContract type_

-- |Wraps a Typed JavaScript module (after type-erasure) with contracts. The
-- result is a single function-application statement.
toInterface :: Env
            -> [InterfaceItem]
toInterface env = map toExport (M.toList env) where
  toExport (v,t) = InterfaceExport v noPos
                                   (toContract' t)
  toContract' Nothing = error "Contracts.hs : export without type"
  toContract' (Just (type_, _, _)) = toContract type_

-- |Wraps a Typed JavaScript module (after type-erasure) with contracts. The
-- result is a single function-application statement.
toInterface env = map toExport (M.toList env) where
  toExport (v,t) = InterfaceExport v noPos
                                   (toContract' t)
  toContract' Nothing = error "Contracts.hs : export without type"
  toContract' (Just (type_, _, _)) = toContract type_

-- |Wraps a Typed JavaScript module (after type-erasure) with contracts. The
-- result is a single function-application statement.