On Fri, Jun 5, 2015 at 12:26 PM, Matt Oliveri <[email protected]> wrote: > On Fri, Jun 5, 2015 at 5:46 AM, Keean Schupke <[email protected]> wrote: >> I don't understand, you just use type-classes: >> >> area :: (RightTriangle a b, Numeric b) => a -> b >> >> RightTrianlge is a constraint on the polygon "a" with points of type "b" >> (Int or Float etc). > > This doesn't add up. If a's a polygon, what is (a -> b)? How do you > take arguments that are elements of a polygon? > > Or did you mean for "a" to be some type that can represent right > triangles, and not an element of a generic polygon type? That would > make more sense. > >> Only the algorithm used in areaOfRightTriangle knows the type of triangle >> required for the area operation, not the triangle itself. >> >> I can have other triangle area definitions too: >> >> area :: (Square a b, Numeric b) => a -> b >> >> WIth suitable overloads I can call 'area' on any polygon, and I will get the >> most efficient algorithm for that type of polygon automatically. > > Well first of all, Matt Rice started with just Triangle, hard-coded to > have three points. If you start with polygon, then yeah, you could > refine down to triangles, right triangles, squares, regular septagons, > or whatever. > > You have a point about wanting to be able to optimize area for > particular polygon types. Type classes may indeed be better than > refinements for this. I didn't mean to argue otherwise. This started > as an example of how you _could_ use refinement types, I thought. > (Since this is the "refinement types" thread.)
In general that was intended to job peoples memory about the example I used in the previous thread where this same issue had come up before having (different assertions for the values of related types), I wasn't really trying to use it as an example of a refinement type specifically _______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
