The following fails to compile:
module Main where
import Text.JSON (JSObject, JSValue)
main = print "hello world"
getObject :: JSValue -> JSObject JSValue
getObject (JSObject x) = x
Giving the error:
Not in scope: data constructor `JSObject'
But removing the import list allows it compilation to success succeed (even though JSObject
was imported above)
module Main where
import Text.JSON
main = print "hello world"
getObject :: JSValue -> JSObject JSValue
getObject (JSObject x) = x
Why is GHC (7.4.2) ignoring my import of JSObject
?
If you write import Text.JSON (JSObject)
you only import type, not the constructors it has. To import constructurs do import Text.JSON (JSObject(..))
or instead of ..
specify comma-separated list of constructor names you wish to use, eg Text.JSON(JSObject(Cons1, Cons2))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.