[Haskell-cafe] n00b question: defining datatype
Thomas DuBuisson
thomas.dubuisson at gmail.com
Thu Jul 23 14:49:20 EDT 2009
> data Task = Task { title :: String, completed :: Bool, subtasks :: [Task] }
> But that's not really right, because obviously, some tasks don't have
As Jake said - that's fine and you can still pattern match on the null
([]) taskes when looking for tasks without subtaskes.
> data Task = Task { title :: String, completed :: Bool } | TaskWithSubtasks {
> title :: String, completed :: Bool, subtasks :: [Task] }
> It's a bit more accurate, but it's repeating things, which is ok with a
> simple type. Could anyone suggest a better way to define this? If I was
> using C#, which I'm far more familiar with, I could overload the constructor
> and refer to the smaller constructor.
So do you want:
data Job = Job {title :: String, completed :: Bool }
data Task = Task Job | MasterTask String [Job]
Tom
More information about the Haskell-Cafe
mailing list