[Haskell-beginners] How do I give a type for this code?
Daniel Trstenjak
daniel.trstenjak at gmail.com
Fri Oct 18 08:38:02 UTC 2013
Hi Todd,
On Thu, Oct 17, 2013 at 09:58:08PM -0700, Todd Wilson wrote:
> Thanks, Daniel, for your suggestion, but I think it misses a key aspect of
> my situation (unless I've misunderstood). Every model is supposed to be a
> quadruple (m, q, f, p), with m a list, q an element of m, f a list of
> ordered pairs of elements of m, and p a sublist of m. By contrast, it
> looks like your definition makes a model either a single element, or a
> single pair, or a single list, etc.
> --Todd
Sorry, I've been rushing a bit.
type Model a = ([a], a, [(a,a)], [a]) -- a is the "base type"
The main problem is, that you can't use different base types for your Model at once.
If you want to support '()', 'a', '(a,a)' and '[a]', than you need one type to abstract
over them.
data BaseType a = Unit -- ()
| Single a -- a
| Product (a,a) -- (a,a)
| Power [a] -- [a]
And now you define your Model by using the BaseType:
type Model' a = Model (BaseType a)
Greetings,
Daniel
More information about the Beginners
mailing list