git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix finally tagless encoding bug, add example.
commit3339928953d482615bd77a5e79734993bb2ea75d authorPhil Freeman <paf31@cantab.net> dateTue 11 Mar 2014, 20:33 (13 years ago) parent63d4595
2 files changed+27
examples/passing/FinalTagless.purs+22 src/Language/PureScript/Sugar/BindingGroups.hs+5
examples/passing/FinalTagless.pursnew file+22
@@ -0,0 +1,22 @@
1+module Main where
2+
3+import Prelude
4+
5+class E e where
6+ num :: Number -> e Number
7+ add :: e Number -> e Number -> e Number
8+
9+type Expr a = forall e. (E e) => e a
10+
11+data Id a = Id a
12+
13+instance exprId :: E Id where
14+ num = Id
15+ add (Id n) (Id m) = Id (n + m)
16+
17+runId (Id a) = a
18+
19+three :: Expr Number
20+three = add (num 1) (num 2)
21+
22+main = Debug.Trace.print $ runId three
src/Language/PureScript/Sugar/BindingGroups.hs+5
@@ -25,6 +25,7 @@ import Data.Data
2525import Data.Graph
2626import Data.Generics
2727import Data.List (nub, intersect)
28+import Data.Maybe (mapMaybe)
2829import Control.Applicative ((<$>), (<*>), pure)
2930
3031import Language.PureScript.Declarations
@@ -89,6 +90,10 @@ usedProperNames :: (Data d) => ModuleName -> d -> [ProperName]
8990usedProperNames moduleName = nub . everything (++) (mkQ [] usedNames)
9091 where
9192 usedNames :: Type -> [ProperName]
93+ usedNames (ConstrainedType constraints _) = flip mapMaybe constraints $ \qual ->
94+ case qual of
95+ (Qualified (Just moduleName') name, _) | moduleName == moduleName' -> Just name
96+ _ -> Nothing
9297 usedNames (TypeConstructor (Qualified (Just moduleName') name)) | moduleName == moduleName' = [name]
9398 usedNames _ = []
9499