@@ -5,7 +5,7 @@ import Control.Applicative ((<$>),(<*>))
55import Control.Monad (liftM,mapM)
66import Data.Char (isUpper,isLower)
77import Data.Maybe (fromMaybe)
8−import Data.List (lookup)
8+import Data.List (lookup,intercalate)
99import Text.Parsec
1010import Text.Parsec.Indent
1111
@@ -18,6 +18,7 @@ data ParseType = VarPT String
1818 | LambdaPT ParseType ParseType
1919 | ADTPT String [ParseType]
2020 | RecordPT (Maybe ParseType) [(String,ParseType)]
21+ deriving (Show)
2122
2223listPT t = ADTPT "List" [t]
2324tuplePT ts = ADTPT ("Tuple" ++ show (length ts)) ts
@@ -150,18 +151,20 @@ toDatatype name args tcs = Datatype name [1..n] <$> mapM toC tcs
150151toForeignType (LambdaPT t1 t2) =
151152 fail $ "Elm's JavaScript event interface does not yet handle functions. " ++
152153 "Only simple values can be imported and exported in this release."
153− --LambdaT <$> toForeignType t1 <*> toForeignType t2
154−toForeignType (ADTPT name args)
155− | isJsStructure name = ADT name <$> mapM toForeignType args
156− | otherwise =
157− Left $ "'" ++ name ++ "' is not an exportable type " ++
158− "constructor. Only 'JSArray' and 'JSTupleN' are exportable."
154+
155+toForeignType (ADTPT "JSArray" args) =
156+ ADT "JSArray" <$> mapM toForeignType args
157+
158+toForeignType (ADTPT name _) =
159+ Left $ "'" ++ name ++ "' is not an exportable type " ++
160+ "constructor. Only 'JSArray' is exportable."
159161
160162toForeignType (VarPT x@(c:_))
163+ | x `elem` jsTypes = Right (ADT x [])
161164 | isLower c =
162− Left "All exported types must be concrete types (JSNumber, JSString, etc.)"
163− | x `elem` ["JSString","JSNumber","JSElement","JSBool"] = Right (ADT x [])
164− | otherwise = Left $ "'" ++ x ++ "' is not an exportable type. Only JSTypes are exportable."
165−
166−isJsStructure name = name == "JSArray" || isTuple
167− where isTuple = "JSTuple" == take 7 name && drop 7 name `elem` map show [2..5]
165+ Left $ "All exported types must be concrete types." ++ msg
166+ | otherwise =
167+ Left $ "'" ++ x ++ "' is not an exportable type." ++ msg
168+ where
169+ msg = " The following types are exportable: " ++ intercalate ", " jsTypes
170+ jsTypes = ["JSString","JSNumber","JSElement","JSBool","JSObject"]