Skip to content

Commit 0604bc1

Browse files
committed
Initial work on desugaring type classes into dictionaries
1 parent 47eba26 commit 0604bc1

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

purescript.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ library
3434
Language.PureScript.Sugar.TypeDeclarations
3535
Language.PureScript.Sugar.BindingGroups
3636
Language.PureScript.Sugar.Operators
37+
Language.PureScript.Sugar.TypeClasses
3738
Language.PureScript.CodeGen
3839
Language.PureScript.CodeGen.Externs
3940
Language.PureScript.CodeGen.JS

src/Language/PureScript/Sugar.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import Language.PureScript.Sugar.DoNotation as S
2323
import Language.PureScript.Sugar.CaseDeclarations as S
2424
import Language.PureScript.Sugar.TypeDeclarations as S
2525
import Language.PureScript.Sugar.BindingGroups as S
26+
import Language.PureScript.Sugar.TypeClasses as S
2627

2728
desugar :: [Module] -> Either String [Module]
28-
desugar = rebracket
29+
desugar = return . desugarTypeClasses
30+
>=> rebracket
2931
>=> desugarDo
3032
>=> desugarCasesModule
3133
>=> desugarTypeDeclarationsModule
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----------------------------------------------------------------------------
2+
--
3+
-- Module : Language.PureScript.Sugar.TypeClasses
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+
-----------------------------------------------------------------------------
14+
15+
module Language.PureScript.Sugar.TypeClasses (
16+
desugarTypeClasses
17+
) where
18+
19+
import Language.PureScript.Declarations
20+
21+
desugarTypeClasses :: [Module] -> [Module]
22+
desugarTypeClasses = map desugarModule
23+
24+
desugarModule :: Module -> Module
25+
desugarModule (Module name decls) = Module name $ concatMap desugarDecl decls
26+
27+
desugarDecl :: Declaration -> [Declaration]
28+
desugarDecl other = [other]

src/Language/PureScript/TypeChecker.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ typeCheckAll currentModule (ImportDeclaration moduleName idents : rest) = do
185185
constructs (Function _ ty) pn = ty `constructs` pn
186186
constructs (TypeApp ty _) pn = ty `constructs` pn
187187
constructs fn _ = error $ "Invalid arguments to constructs: " ++ show fn
188+
typeCheckAll moduleName (TypeClassDeclaration name arg decls : rest) = do
189+
typeCheckAll moduleName rest
190+
typeCheckAll moduleName (TypeInstanceDeclaration name ty decls : rest) = do
191+
typeCheckAll moduleName rest
188192

189193
qualifyAllUnqualifiedNames :: (Data d) => ModuleName -> Environment -> d -> d
190194
qualifyAllUnqualifiedNames mn env = everywhere (mkT go)

0 commit comments

Comments
 (0)