I wrote some simple module in Haskell and then import
it in other file. Then I'm trying to use functions with data constructors from my module — there is an error Not in scope: data constructor: <value>
. How can I fix it?
Note: when I'm using it in interpreter after importing — all is good without errors.
My module Test.hs
:
module Test (test_f) where
data Test_Data = T|U|F deriving (Show, Eq)
test_f x
| x == T = T
| otherwise = F
And my file file.hs
:
import Test
some_func = test_f
No error if I'm writing in interpreter:
> :l Test
> test_f T
T
In interpreter I'm trying to execute some_func T
, but there is an error. And how can I use class Test_Data
in my file to describe annotations?
You aren't exporting it from your module:
module Test (test_f, Test_Data(..)) where
The (..)
part says "export all constructors for TestData
".
You have an explicit export list in your module Test
:
module Test (test_f) where
The export list (test_f)
states that you want to export the function test_f
and nothing else. In particular, the datatype Test_Data
and its constructors are hidden.
To fix this, either remove the export list like this:
module Test where
Now all things will be exported.
Or add the datatype and its constructors to the export list like this:
module Test (test_f, Test_Data(..)) where
The notation Test_Data(..)
exports a datatype with all corresponding constructors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With