Skip to content

Commit e7d219e

Browse files
committed
Fix Category bug purescript#158
1 parent 98d1989 commit e7d219e

File tree

7 files changed

+23
-9
lines changed

7 files changed

+23
-9
lines changed

examples/passing/Category.purs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Category where
2+
3+
class Category c where
4+
id :: forall x. c x x
5+
(<|) :: forall x y z. c y z -> c x y -> c x z
6+
7+
instance Category (->) where
8+
id = Prelude.id
9+
(<|) = Prelude.(<|)
10+
11+
module Main where
12+
13+
import Category
14+
15+
main = Trace.trace (id "Done")

libraries/prelude/prelude.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module Prelude where
33
foreign import data String :: *
44
foreign import data Number :: *
55
foreign import data Boolean :: *
6-
foreign import data [] :: * -> *
7-
foreign import data (->) :: * -> * -> *
6+
foreign import data Array :: * -> *
7+
foreign import data Function :: * -> * -> *
88

99
id :: forall a. a -> a
1010
id = \x -> x

src/Language/PureScript/Parser/Common.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,6 @@ natural = PT.natural tokenParser
239239
properName :: P.Parsec String u ProperName
240240
properName = lexeme $ ProperName <$> P.try ((:) <$> P.upper <*> many (PT.identLetter langDef) P.<?> "name")
241241

242-
properNameOrExternalType :: P.Parsec String u ProperName
243-
properNameOrExternalType = P.try properName <|> (ProperName <$> (P.try (lexeme $ P.string "[]") <|> (lexeme $ P.string "(->)")))
244-
245242
-- |
246243
-- Parse a qualified name, i.e. M.name or just name
247244
--

src/Language/PureScript/Parser/Declarations.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ parseValueDeclaration =
6464

6565
parseExternDeclaration :: P.Parsec String ParseState Declaration
6666
parseExternDeclaration = P.try (reserved "foreign") *> indented *> (reserved "import") *> indented *>
67-
(ExternDataDeclaration <$> (P.try (reserved "data") *> indented *> properNameOrExternalType)
67+
(ExternDataDeclaration <$> (P.try (reserved "data") *> indented *> properName)
6868
<*> (lexeme (indented *> P.string "::") *> parseKind)
6969
<|> do ident <- parseNonReservedIdent
7070
js <- P.optionMaybe (parseJSLiteral <$> stringLiteral)

src/Language/PureScript/Pretty/Types.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ typeLiterals = mkPattern match
3333
where
3434
match (Object row) = Just $ "{ " ++ prettyPrintType row ++ " }"
3535
match (TypeVar var) = Just var
36+
match (TypeApp arr ty) | arr == tyArray = Just $ "[" ++ prettyPrintType ty ++ "]"
3637
match (TypeConstructor ctor) = Just $ show ctor
3738
match (TUnknown (TypedUnknown (Unknown u))) = Just $ 'u' : show u
3839
match (Skolem s) = Just $ 's' : show s

src/Language/PureScript/TypeChecker/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,8 @@ checkFunctionApplication fn fnTy arg ret = rethrow errorMessage $ checkFunctionA
922922
-- Check the type of a function application
923923
--
924924
checkFunctionApplication' :: Value -> Type -> Value -> Type -> UnifyT Check Value
925-
checkFunctionApplication' fn (TypeApp (TypeApp t argTy) retTy) arg ret | t == tyFunction = do
925+
checkFunctionApplication' fn (TypeApp (TypeApp tyFunction' argTy) retTy) arg ret = do
926+
tyFunction' ?= tyFunction
926927
arg' <- check arg argTy
927928
_ <- subsumes Nothing retTy ret
928929
return $ App fn arg'

src/Language/PureScript/Types.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ data Type
7777
-- Type constructor for functions
7878
--
7979
tyFunction :: Type
80-
tyFunction = TypeConstructor $ (Qualified $ Just $ ModuleName $ ProperName "Prelude") (ProperName "(->)")
80+
tyFunction = TypeConstructor $ (Qualified $ Just $ ModuleName $ ProperName "Prelude") (ProperName "Function")
8181

8282
-- |
8383
-- Type constructor for strings
@@ -101,7 +101,7 @@ tyBoolean = TypeConstructor $ (Qualified $ Just $ ModuleName $ ProperName "Prelu
101101
-- Type constructor for arrays
102102
--
103103
tyArray :: Type
104-
tyArray = TypeConstructor $ (Qualified $ Just $ ModuleName $ ProperName "Prelude") (ProperName "[]")
104+
tyArray = TypeConstructor $ (Qualified $ Just $ ModuleName $ ProperName "Prelude") (ProperName "Array")
105105

106106
-- |
107107
-- Smart constructor for function types

0 commit comments

Comments
 (0)