git.iko.soy/rowtype-yoga/purescript-native
on 8877913 help sign in
32 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) where
19import Control.Applicative
20import Control.Monad.Error.Class
22import Language.PureScript.Declarations
23import Language.PureScript.Values
25desugarTypeDeclarations :: [Declaration] -> Either String [Declaration]
26desugarTypeDeclarations (TypeDeclaration name ty : ValueDeclaration name' [] Nothing val : rest) | name == name' =
27 desugarTypeDeclarations (ValueDeclaration name [] Nothing (TypedValue val ty) : rest)
28desugarTypeDeclarations (TypeDeclaration name _ : _) = throwError $ "Orphan type declaration for " ++ show name
29desugarTypeDeclarations (ModuleDeclaration name ds:ds') = (:) <$> (ModuleDeclaration name <$> desugarTypeDeclarations ds)
30 <*> desugarTypeDeclarations ds'
31desugarTypeDeclarations (d:ds) = (:) d <$> desugarTypeDeclarations ds
32desugarTypeDeclarations [] = return []