agentm / project-m36

Project: M36 Relational Algebra Engine
The Unlicense
876 stars 47 forks source link

AttributeAndTypeNameExpr vs NakedAttributeExpr #356

Closed YuMingLiao closed 1 year ago

YuMingLiao commented 1 year ago

In client side, If I Define ... [AttributeAndTypeNameExpr ...] with an non-existent datatype, I get NoSuchTypeConstructorError. I found this error is easier for me to understand.

If I Define ...[NakedAttributeExpr ...] with an non-existent datatype, I get TypeConstructorAtomTypeMismatch.

What's their difference? (project-m36-typed uses NakedAttributeExpr to define.)

agentm commented 1 year ago

I am able to reproduce this with:

{-# LANGUAGE OverloadedStrings #-}
import ProjectM36.Client

main :: IO ()
main = do
  Right conn <- connectProjectM36 (InProcessConnectionInfo NoPersistence emptyNotificationCallback [])
  Right sessionId <- createSessionAtHead conn defaultHeadName
  executeDatabaseContextExpr sessionId conn (Define "x" [AttributeAndTypeNameExpr "a" (ADTypeConstructor "Nope" []) ()]) >>= print
  executeDatabaseContextExpr sessionId conn (Define "y" [NakedAttributeExpr (Attribute "b" (ConstructedAtomType "Spam" mempty))]) >>= print
$ ./Test356 
"SPAM"
Left (NoSuchTypeConstructorError "Nope")
Left (TypeConstructorAtomTypeMismatch "Spam" (ConstructedAtomType "Spam" (fromList [])))
agentm commented 1 year ago

The difference in the errors is that, in some contexts when we have multiple NakedAtomExprs, we know what type is expected, so we can return an error explaining which type was expected. In the above context though, the comparison type doesn't exist. I'll improve the error.

agentm commented 1 year ago

I think that you are right. In the context of an unknown type constructor, the correct error is NoSuchTypeConstructorError.

YuMingLiao commented 1 year ago

Thanks for the clarification and fixing. Amazing project!