-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support nominally distinct Haskell types with identical copilot types #58
Comments
This is a feature that is requested before (#56), and something we definitely want to implement. Having this amount of type-safety will really introduce a huge benefit over using C. Indeed With the limited time we can currently spent on developing Copilot, we focus mostly on bugfixing and cleaning the project up. Copilot's types are one of the things that we want to try to simplify, most likely aiding in implementing more strict types. |
I'm too noob to make any meaningful contribution in this space. How are you making up for the lack of Haskell types currently? It seems that Copilot programs currently are forced to use the C types defined in Type. Is there some way, for example, to (maybe unsafely) cast a Haskell Enum to a Word32? |
Sorry, but wouldn't it be possible to do something like this?
Where the binary class Then you could say that any type can be reduced to itself, and a new type would only need to define an instance saying that it can be reduced to the type it encloses? EDIT: |
We may want to look into https://hackage.haskell.org/package/base-4.14.1.0/docs/Data-Coerce.html#t:Coercible. We might be able to provide instances for
|
By the way, I have no idea why we require the |
I wasn't able to get the |
Tagging @avieth . Maybe he knows. There may be a way to simplify his solution using |
Motivation
It would be great to have domain-specific Haskell types in streams, as this can give extra type safety in the high-level model that, with correct code generation, holds true even in the less-strongly-typed target language. Take this simple example with three nominally and semantically distinct types with the same representation:
I've judged that this is not possible presently, simply because of the definition of
Typed
To get
Typed Time_ms
, for example, you need to give aType Time_ms
, but there is no such thing: it's not a struct or an array, it's aWord32
, but the type parameter must beTime_ms
.How could it be done
Needless to say, this would be a massively breaking change worthy of a new major version number.
The idea is to define a kind for types in the object language (Haskell being the meta language) and use this to parameterize Haskell types which represent the object language types and values of those types. The
Typed
class would then become (ignore bad choice of names)and we could get this for our example
Here's what
CType
,CTypeRep
, andCValRep
could be (as a bonus, we also get support union and enum types)The text was updated successfully, but these errors were encountered: