git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Only make composition suggestion on `object . app function`
commit9c61180776294087cd17dac5a5cfc2b7a3da2093 authorMichael Gilliland <mjg.py3@gmail.com> dateSat 18 Jul 2015, 17:23 (11 years ago) parentfcb66d4
5 files changed+31−5
examples/failing/DoNotSuggestComposition.purs+10 examples/failing/DoNotSuggestComposition2.purs+3 examples/failing/SuggestComposition.purs+5 src/Language/PureScript/Environment.hs+11−3 src/Language/PureScript/Errors.hs+2−2
examples/failing/DoNotSuggestComposition.pursnew file+10
@@ -0,0 +1,10 @@
1+module DoNotSuggestComposition where
2+
3+import Prelude
4+
5+x = { y: 3 }
6+
7+foo :: String -> String
8+foo y = y
9+
10+bar = foo x
examples/failing/DoNotSuggestComposition2.pursnew file+3
@@ -0,0 +1,3 @@
1+module DoNotSuggestComposition2 where
2+
3+foo = let x = { y: 3 } in x 2
examples/failing/SuggestComposition.pursnew file+5
@@ -0,0 +1,5 @@
1+module SuggestComposition where
2+
3+import Prelude
4+
5+f = g . g where g = (+1)
src/Language/PureScript/Environment.hs+11−3
@@ -214,9 +214,17 @@ tyObject = primTy "Object"
214214-- Check whether a type is an object
215215--
216216isObject :: Type -> Bool
217−isObject = (==) tyObject . extract
218− where extract (TypeApp t _) = t
219− extract t = t
217+isObject = isTypeOrApplied tyObject
218+
219+-- |
220+-- Check whether a type is a function
221+--
222+isFunction :: Type -> Bool
223+isFunction = isTypeOrApplied tyFunction
224+
225+isTypeOrApplied :: Type -> Type -> Bool
226+isTypeOrApplied t1 (TypeApp t2 _) = t1 == t2
227+isTypeOrApplied t1 t2 = t1 == t2
220228
221229-- |
222230-- Smart constructor for function types
src/Language/PureScript/Errors.hs+2−2
@@ -35,7 +35,7 @@ import Control.Monad.Trans.State.Lazy
3535import Control.Arrow(first)
3636
3737import Language.PureScript.AST
38−import Language.PureScript.Environment (isObject)
38+import Language.PureScript.Environment (isObject, isFunction)
3939import Language.PureScript.Pretty
4040import Language.PureScript.Types
4141import Language.PureScript.Names
@@ -670,7 +670,7 @@ prettyPrintSingleError full level e = prettyPrintErrorMessage <$> onTypesInError
670670 , indent . line $ "import " ++ show im ++ " hiding (" ++ nm ++ ")"
671671 ]
672672 suggestions' (TypesDoNotUnify t1 t2)
673− | any isObject [t1, t2] = [line "Note that function composition in PureScript is defined using (<<<)"]
673+ | isObject t1 && isFunction t2 = [line "Note that function composition in PureScript is defined using (<<<)"]
674674 | otherwise = []
675675 suggestions' _ = []
676676