[Haskell-cafe] Basic Haskell Types Question
Adam Wyner
adam at wyner.info
Fri Sep 16 08:19:18 EDT 2005
Hi,
I have a basic question about how output types are reported. I'm using
Hugs.
Suppose I have the following, where the type String is predefined in
the Prelude as [Char].
type PropList = [String]
atomicProps1 :: PropList
atomicProps1 = ["prop1"]
And I have a function on expressions of type PropList which takes every
string
from the input list and prefixes the string "neg-" to it.
negationAtomicProps :: PropList -> PropList
negationAtomicProps inPropsList = [ "neg-" ++ inString | inString <-
inPropsList]
So, with the following, I get the right result:
> negationAtomicProps atomicProps1
["neg-prop1"]
The types for the parts are right:
> :t negationAtomicProps
negationAtomicProps :: PropList -> PropList
> :t atomicProps1
atomicProps1 :: PropList
But, what I don't understand or like is that the type of the whole
is given as [[Char]], not what I thought it would be, namely PropList.
Nor is it [String].
> :t negationAtomicProps atomicProps1
negationAtomicProps atomicProps1 :: [[Char]]
I really want to get the following sort of report for the type:
negationAtomicProps atomicProps1 :: PropList
The reason I want this is that in more complex cases, it will be easier
to see what is going wrong (as the functions are developed) if I can see
the types I want.
Am I supposed to be using newtype or data declarations here? How would
I do this? I looked around for information in the usual sources,
but haven't found an answer.
Thanks,
Adam Wyner
More information about the Haskell-Cafe
mailing list