agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
895 stars 48 forks source link

How to create a Type Constructor? #235

Closed YuMingLiao closed 5 years ago

YuMingLiao commented 5 years ago

I was adding a feature in project-m36-typed. I want to auto-derive all the new datatypes found in a schema. And there is a type in DbRecord a to represent an id of various types: data RecordId a = RecordId Text

In ProjectM36, am I allowed to create a type whose type variable isn't used in data?

TutorialD (master/main): data RecordId a = RecordId Text
ERR: DataConstructorUsesUndeclaredTypeVariable "a"
TutorialD (master/main): data RecordId a = RecordId a

┌───────────────────────────────────────────┐                                                                                     │"Maybe"              │
││DataConstructor::Text                      │                                                                                     │                     │
│├───────────────────────────────────────────┤                                                                                     │                     │
││"Just DataConstructorDefTypeVarNameArg "a""│                                                                                     │                     │
││"Nothing"                                  │                                                                                     │                     │
│└───────────────────────────────────────────┘                                                                                     │                     │

┌──────────────────────────────────────────────────────────────────┐                                                              │"RecordId"           │
││DataConstructor::Text                                             │                                                              │                     │
│├──────────────────────────────────────────────────────────────────┤                                                              │                     │
││"RecordId DataConstructorDefTypeConstructorArg (TypeVariable "a")"│                                                              │    
YuMingLiao commented 5 years ago

Actually, I don't need phantom types. I can create a type constructor by toAddTypeEpxr now. It works well. Don't know what happened to me. :p Please ignore this issue.

agentm commented 5 years ago

Right. As you discovered, phantom types are not supported right now, though I can foresee how they might be useful.

The type variable resolution is actually somewhat broken right now- #226. I need to create a mirror type variable dictionary (like GHC does with a becoming a0 in error messages), but the workaround is easy enough that I haven't spent the time on it.

YuMingLiao commented 5 years ago

I see. Thank you for clarifying it!