Re: [Haskell-beginners] How do I give a type for this code?

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 On Thu, Oct 17, 2013 at 4:12 AM, Daniel Trstenjak < daniel.trstenjak@gmail.com> wrote:
Hi Todd,
the problem is, that 'model_of' tries to return different types: Model a, Model (a,a) and Model [a].
I think you have to use some kind of ADT also for the Model, like you already did for ModName.
Something like:
data Model a = Model a | ProductModel (a,a) | PowerModel [a] ...
Greetings, Daniel _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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
participants (2)
-
Daniel Trstenjak
-
Todd Wilson