I am going through "Haskell Programming from first principles" and found an exercise asking if the following [code slightly edited here] was valid:
module Test where
type Subject = String
type Verb = String
type Object = String
data Sentence =
Sentence Subject Verb Object
deriving (Eq, Show)
a1 = Sentence "I" "like" "cheese"
a2 = Sentence "I" "scream"
My expectation was initially that the code would fail, because in the definition of a2, Sentence only had two arguments. But found that GHCi was happy to load the module. I did a little experimentation and found that I could now type
a3 = a2 "icecream"
and a3 (typed into GHCi) would print Sentence "I" "scream" "icecream". Also, if I inquire the types of a2 I get a2 :: Object -> Sentence. So if I understand correctly, a2 is behaving exactly like a partially-applied function.
Question therefore is: Is a type constructor really just a function (that returns a type value) in all situations - distinguished from a 'normal' function only in that it has to start with an upper-case character?
:t Justin ghci. - michidcase mySentence of (Sentence s v o) -> ...for example - hereSentenceis used for pattern-matching and you cannot insert a function there (well there are extensions ... but on a basic level you cannot) - Random Dev