Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: How do I give a type for this code? (Todd Wilson)
2. Re: How do I give a type for this code? (Daniel Trstenjak)
----------------------------------------------------------------------
Message: 1
Date: Thu, 17 Oct 2013 21:58:08 -0700
From: Todd Wilson <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How do I give a type for this code?
Message-ID:
<CA+-99o+me0X1OQWrQow-_xiO=kk52yrp42unwt7xub27s5v...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
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 <
[email protected]> 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
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20131017/51e40dc7/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 18 Oct 2013 10:38:02 +0200
From: Daniel Trstenjak <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How do I give a type for this code?
Message-ID: <20131018083802.GA3092@machine>
Content-Type: text/plain; charset=iso-8859-1
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
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 64, Issue 29
*****************************************