[curry] Re: How to interpret a data type with no RHS

From: Finn Teegen <fte_at_informatik.uni-kiel.de>
Date: Mon, 27 May 2019 16:02:32 +0200

Hi Andy,

Wolfgang perfectly described the meaning of a data type with an empty
right hand side. In order to distinguish such data types without values
from those that are externally implemented in the runtime system, we
introduced a new syntax for the latter. For example, the predefined type
`Int` is now declared as follows in the `Prelude`.

external data Int

Since we did not want to change the definition of FlatCurry too much (or
even at all), the front end still translates the definition above into a
type without any constructors in FlatCurry. To implement the distinction
nonetheless, a single constructor is added to data types without a right
hand side. And since the name of this constructor must not clash with
other defined operations, the front end uses a special prefix, namely
"_Constr#" (which is of course not legal in Curry, but in FlatCurry).
However, this translation is strictly speaking wrong as Wolfgang stated.
Correct translations of the data type

data A

would be

data A = A !A

or

newtype A = A A.

Unfortunately, both of these translations are not possible at the moment
due to Curry's lacking support of bang patterns or recursive newtypes.
The current solution therefore is just a temporary one. By the way, the
change in the translation was not related to the introduction of type
classes or in any way connected to them. The original motivation was an
issue with our KiCS2 compiler.

Anyway, we plan to add newtypes to FlatCurry in the near future (this
plan is related to type classes). This way the second translation of
data type with an empty right hand side would become possible.
Alternatively, it would of course also make sense to distinguish
externally defined data types from those with an empty right hand in
FlatCurry itself.

I hope this explanation helps a bit.

Regards,
Finn

On 27/05/19 09:49, Wolfgang Lux wrote:
> Hi Andy,
>
>> I can define an empty data type in Curry, e.g.:
>>
>> data A
>>
>> The built-in types such as Char, Int and Float are defined this way in the Prelude. Prior to the introduction of typeclasses the Curry frontend would translate this to a FlatCurry Type with no constructors. Newer versions produce a type with one constructor named “_Constr#A”.
>>
>> I’d like to understand how to interpret this. Is the above legal Curry? Is this perhaps a forward declaration or opaque type? Can the type, A, be defined later? If so, would it have to be defined in the same module? Is this documented somewhere?
>>
>> I’m tempted to reject such a declaration unless the system can find a built-in definition but I don’t want to reject legal programs.
>
> data type declarations with an empty right hand side are mentioned in the language report as representing external data types.
> Literally, a data type with no right hand side just represents the uninhabitated type, i.e., a type that has no values. This type is not very useful on itself, but may have some uses in some cornerstone cases as a base type in some libraries. The fact that the user/compiler cannot create values of such a type makes data types without a right hand side an obvious representation for abstract types, whose concrete representation is not available to the compiler. So, unless you plan to not provide an interface to external code I think you should support such types.
> With the reasoning above the translation of such types into a type with a single constructor on the right hand side feels outright wrong to me, as the type would become equivalent to the unit type () (unless the constructor also has some arguments), but maybe Michael will shed some light on this.
>
> Wolfgang
> _______________________________________________
> curry mailing list -- curry_at_lists.rwth-aachen.de
> To unsubscribe send an email to curry-leave_at_lists.rwth-aachen.de
> https://lists.rwth-aachen.de/postorius/lists/curry.lists.rwth-aachen.de
>
_______________________________________________
curry mailing list -- curry_at_lists.rwth-aachen.de
To unsubscribe send an email to curry-leave_at_lists.rwth-aachen.de
https://lists.rwth-aachen.de/postorius/lists/curry.lists.rwth-aachen.de
Received on Mo Mai 27 2019 - 17:03:33 CEST

This archive was generated by hypermail 2.3.0 : Do Jun 20 2024 - 07:15:14 CEST