Please tell me what is the problem?
data Stack' v = Stack' [v] Int deriving (Show) ... type StackInt = Stack' Int main = print(StackInt [1,2,3] 4)
The error i am getting is
Not in scope: data constructor `Stackint'
What is wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It looks to me like you are confusing the concepts of types and constructors, this is a common problem as they live in separate namespaces and are often given the same name. In the Haskell expression
say, you are actually defining the type
SomeTypeand a constructorSomeType. The type is not a function in the normal sense, but the constructor is. If you asked ghci for the type of SomeType you would get this:Now, a
typedeclaration is just a shorthand for a longer type definition, in your case makingStackInta synonym ofStack' Int. But in order to construct a value of this type you still need to use the constructorStack'(which has type[v] -> Int -> Stack' v). So your code should beIf you wanted to be sure that the type was
Stack' Intthen you could add a functionEDIT: Not also that I’ve written
stackInt list i = Stack' list ifor transparency here, but you can write it more elegantly just asstackInt = Stack'. It is the type constraint that makes sure that you get the right type here.You could also have both the new function and the type synonym if you wanted, ie