git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add array example
commitf3d1bb0704ee52ae1a7068edad766cf125648507 authorPhil Freeman <paf31@cantab.net> dateThu 16 Jan 2014, 21:07 (13 years ago) parentcc947bd
3 files changed+9−3
examples/passing/TypeClasses.purs+5 src/Language/PureScript/Sugar/TypeClasses.hs+1−1 src/Language/PureScript/TypeChecker/Types.hs+3−2
examples/passing/TypeClasses.purs+5
@@ -40,3 +40,8 @@ test4 = ret 1
4040
4141test5 = Just 1 >>= \n -> ret (n + 1)
4242
43+module TypeClasses2 where
44+
45+instance (TypeClasses.Show a) => TypeClasses.Show [a] where
46+ show [] = "[]"
47+ show (x:xs) = TypeClasses.show x ++ ", " ++ TypeClasses.show xs
src/Language/PureScript/Sugar/TypeClasses.hs+1−1
@@ -93,7 +93,7 @@ typeInstanceDictionaryDeclaration mn deps name ty decls = do
9393typeInstanceDictionaryEntryDeclaration :: ModuleName -> [(Qualified ProperName, Type)] -> Qualified ProperName -> Type -> Declaration -> Desugar Declaration
9494typeInstanceDictionaryEntryDeclaration mn deps name ty (ValueDeclaration ident [] _ val) = do
9595 m <- get
96− let valTy = fromMaybe (error "Type class instance dictionary member is missing in typeInstanceDictionaryEntryDeclaration") $
96+ valTy <- lift $ maybe (Left $ "Type class " ++ show name ++ " is undefined. Type class names must be qualified.") Right $
9797 do (arg, members) <- M.lookup (qualify mn name) m
9898 ty' <- lookup (identToJs ident) members
9999 return $ replaceTypeVars arg ty ty'
src/Language/PureScript/TypeChecker/Types.hs+3−2
@@ -192,7 +192,7 @@ entails :: ModuleName -> [TypeClassDictionaryInScope] -> (Qualified ProperName,
192192entails moduleName context goal@(className, ty) = do
193193 env <- getEnv
194194 case go env goal of
195− [] -> throwError $ "No " ++ show className ++ " instance found for " ++ prettyPrintType ty
195+ [] -> throwError $ "No " ++ show className ++ " instance found for " ++ show context
196196 (dict : _) -> return dict
197197 where
198198 go env (className', ty') =
@@ -213,7 +213,8 @@ typeHeadsAreEqual _ _ String String = Just []
213213typeHeadsAreEqual _ _ Number Number = Just []
214214typeHeadsAreEqual _ _ Boolean Boolean = Just []
215215typeHeadsAreEqual _ _ (Skolem s1) (Skolem s2) | s1 == s2 = Just []
216−typeHeadsAreEqual m e (Array ty1) (Array ty2) = typeHeadsAreEqual m e ty1 ty2
216+typeHeadsAreEqual m e (Array (TypeVar v)) (Array ty) = Just [(v, ty)]
217+typeHeadsAreEqual m e (Array ty) (Array (TypeVar v)) = Just [(v, ty)]
217218typeHeadsAreEqual m e (TypeConstructor c1) (TypeConstructor c2) | typeConstructorsAreEqual e m c1 c2 = Just []
218219typeHeadsAreEqual m e (TypeApp h1 (TypeVar v)) (TypeApp h2 arg) = (:) (v, arg) <$> typeHeadsAreEqual m e h1 h2
219220typeHeadsAreEqual m e t1@(TypeApp _ _) t2@(TypeApp _ (TypeVar _)) = typeHeadsAreEqual m e t2 t1