git.iko.soy/rowtype-yoga/purescript-native
on bcc7e77 help sign in
35 lines 1.3 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Language.PureScript.TypeDeclarations
4-- Copyright : (c) Phil Freeman 2013
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- |
12--
13-----------------------------------------------------------------------------
15module Language.PureScript.TypeDeclarations (
16 desugarTypeDeclarations,
17 desugarTypeDeclarationsModule
18) where
20import Control.Applicative
21import Control.Monad.Error.Class
22import Control.Monad (forM)
24import Language.PureScript.Declarations
25import Language.PureScript.Values
27desugarTypeDeclarationsModule :: [Module] -> Either String [Module]
28desugarTypeDeclarationsModule ms = forM ms $ \(Module name ds) -> Module name <$> desugarTypeDeclarations ds
30desugarTypeDeclarations :: [Declaration] -> Either String [Declaration]
31desugarTypeDeclarations (TypeDeclaration name ty : ValueDeclaration name' [] Nothing val : rest) | name == name' =
32 desugarTypeDeclarations (ValueDeclaration name [] Nothing (TypedValue val ty) : rest)
33desugarTypeDeclarations (TypeDeclaration name _ : _) = throwError $ "Orphan type declaration for " ++ show name
34desugarTypeDeclarations (d:ds) = (:) d <$> desugarTypeDeclarations ds
35desugarTypeDeclarations [] = return []