git.iko.soy/rowtype-yoga/purescript-native
on 85a291f help sign in
73 lines 2.4 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Language.PureScript.Sugar
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-- Desugaring passes
13--
14-----------------------------------------------------------------------------
16{-# LANGUAGE FlexibleContexts #-}
18module Language.PureScript.Sugar (desugar, module S) where
20import Control.Monad
21import Control.Category ((>>>))
22import Control.Applicative
23import Control.Monad.Error.Class (MonadError(..))
24import Control.Monad.Supply.Class
26import Language.PureScript.AST
27import Language.PureScript.Errors
29import Language.PureScript.Sugar.BindingGroups as S
30import Language.PureScript.Sugar.CaseDeclarations as S
31import Language.PureScript.Sugar.DoNotation as S
32import Language.PureScript.Sugar.Names as S
33import Language.PureScript.Sugar.ObjectWildcards as S
34import Language.PureScript.Sugar.Operators as S
35import Language.PureScript.Sugar.TypeClasses as S
36import Language.PureScript.Sugar.TypeClasses.Deriving as S
37import Language.PureScript.Sugar.TypeDeclarations as S
39-- |
40-- The desugaring pipeline proceeds as follows:
41--
42-- * Remove signed literals in favour of `negate` applications
43--
44-- * Desugar object literals with wildcards into lambdas
45--
46-- * Desugar operator sections
47--
48-- * Desugar do-notation using the @Prelude.Monad@ type class
49--
50-- * Desugar top-level case declarations into explicit case expressions
51--
52-- * Desugar type declarations into value declarations with explicit type annotations
53--
54-- * Qualify any unqualified names and types
55--
56-- * Rebracket user-defined binary operators
57--
58-- * Introduce type synonyms for type class dictionaries
59--
60-- * Group mutually recursive value and data declarations into binding groups.
61--
62desugar :: (Applicative m, MonadSupply m, MonadError MultipleErrors m) => [Module] -> m [Module]
63desugar = map removeSignedLiterals
64 >>> mapM desugarObjectConstructors
65 >=> mapM desugarOperatorSections
66 >=> mapM desugarDoModule
67 >=> desugarCasesModule
68 >=> desugarTypeDeclarationsModule
69 >=> desugarImports
70 >=> rebracket
71 >=> mapM deriveInstances
72 >=> desugarTypeClasses
73 >=> createBindingGroupsModule