It might not be possible to reference types in other types #64
Replies: 3 comments 3 replies
-
That's right. Presently you can't reference user-defined types in your user-defined types. I plan to lift that limitation. 👌 Just needs a simple dependency analysis and then referencing But recursively defined types present a challenge, so those would in the near-term not be supported. |
Beta Was this translation helpful? Give feedback.
-
@chrisdone Just saw that you added referencing custom types within records and snatched it up into my config to test it out. Nesting record types within records seems to work as expected, but sums seem to have a quirk. If you do this: data MyRecord = MyRecord {sum :: Main.MySum}
data MySum = MySumL | MySumR
main = do
let myRecord = Main.MyRecord {sum = Main.MySumR}
Text.putStrLn "hello world" You'll get an error:
I tried a few different permutations but it seems like the sum must be constructed with the |
Beta Was this translation helpful? Give feedback.
-
Oh, thanks for trying it! Looks like I’ve been inconsistent in a key area in terms of generating the name of the type. It should be qualified, and probably it was not qualified previously in the constructor.
I’ll fix this when I’m back at keyboard.
On Wed, Jan 1, 2025, at 8:06 PM, Michael Xavier wrote:
@chrisdone <https://github.com/chrisdone> Just saw that you added referencing custom types within records and snatched it up into my config to test it out. Nesting record types within records seems to work as expected, but sums seem to have a quirk. If you do this:
data MyRecord = MyRecord {sum :: Main.MySum}
data MySum = MySumL | MySumR
main = do
let myRecord = Main.MyRecord {sum = Main.MySumR}
Text.putStrLn "hello world"
You'll get an error:
`hell: Unification error: Couldn't match type
"Main.MySum"
against type
"MySum"
`
… I tried a few different permutations but it seems like the sum must be constructed with the `Main` module qualifier.
—
Reply to this email directly, view it on GitHub <#64 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAACWC3XXX4CZ7DWS7BC26D2IRDEDAVCNFSM6AAAAABTVAE6N2VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCNZRGIYDKOA>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Given the minimal example file:
You'll get an error along the lines of
Unknown type: TyCon "Sum"
. You get a similar thing if you reference Sum byMain.Sum
. If you instead define some other recordQuux
and add a field toBaz
of that type, you get the same kind of error. Because this affects both records (desugars to a Record type) and sums (desugars to a Variant type), maybe the syntactic sugar allows you to handle the values directly but isn't available to the type system?Beta Was this translation helpful? Give feedback.
All reactions