[Haskell-cafe] Restrict values in type

Daniil Frumin difrumin at gmail.com
Thu Jan 16 14:31:37 UTC 2014


Ah, it is a little bit confusing.

The type (forall repr. (CirclePen repr, RectPen repr) => repr) is
inhabited by a _represtentation_ that can be constructed  both by
'circle' and by 'rectangle'. So we can use any of those two functions
to construct a value of that type. (Such type is FiniteDim for
example). The Arc constructor, on the other hand, accepts only values
of type (forall repr. (CirclePen repr) => repr). We don't know
anything about the concrete representation type, we only know that we
can construct it using 'circle'.

Hth
-dan

On Thu, Jan 16, 2014 at 6:16 PM, Luke Clifton <ltclifton at gmail.com> wrote:
> Thanks, that really cleared up a few of the questions I had about Jake
> McArthurs' code as well. The link you provided was a good read and shed some
> more light on the situation.
>
> The only bit I don't quite understand is why the following code implies an
> "or" relation in the type constraint of repr.
>
>> data Stroke =
>>    Line Point Point (forall repr. (CirclePen repr, RectPen repr) => repr)
>>  | Arc Point Point (forall repr. (CirclePen repr) => repr)
>>  | Spot Point (forall repr.
>>                (CirclePen repr, RectPen repr, ArbitraryPen repr) => repr)
>
> To me this reads that repr should be both a CirclePen and a RectPen in order
> to satisfy the type constraint in the case of Line, but it seems that it is
> accepting a CirclePen or a RectPen (which is the desired behaviour, so I'm
> not complaining).
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Sincerely yours,
-- Daniil


More information about the Haskell-Cafe mailing list