On Fri, Jun 5, 2015 at 5:46 AM, Keean Schupke <ke...@fry-it.com> 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.) _______________________________________________ bitc-dev mailing list bitc-dev@coyotos.org http://www.coyotos.org/mailman/listinfo/bitc-dev