Skip to content

Make non-contextual Code the default #63

@LPTK

Description

@LPTK

It is entirely possible to use Squid without statically checking scopes, similar to MetaOCaml or Dotty's quotes (but of course with more features, like pattern matching).

This simpler mode of usage is less type-safe, but makes many things much easier and less intimidating for beginners. One has to use the OpenCode[T] type (which is a super type of the contextual Code[T,C]), and use .unsafe_asClosedCode whenever one wants to run or compile the piece of code.

However, currently we emphasize the contextual mode of Squid as the default/normal mode, which is intimidating and may scare beginners away. Instead, I think we should promote the simpler interface as the default interface, and reserve the contextual interface for advanced users. This would mean:

  • Changing the type synonyms: OpenCode[T] is long-winded and a bit ugly; we'd like to use Code[T] instead. The new scheme would be: Code[T] for when you do not know the context, ClosedCode[T] for code that is assuredly closed and can be run; OpenCode[T,C] for open code for which we statically track the scope using contextual type C (for advanced users).
    Alternatively, as I previously proposed in LPTK/squid-type-experiments, we could have type synonym in to enable the nice Code[T] in C syntax (meaning Code[T]{ type Ctx >: C }), though that would likely require changes in Squid to look at the Ctx member of code types instead of their C type argument, which may cause weird typing problems down the line.

  • Changing the code types inferred by default: we should have a SimplePredef which is configured to make quasiquotes infer Code[T] types by default, instead of Code[T,C] types; even though OpenCode[T,C] <: Code[T], this still does help with type inference, such as when doing var c = code"0"; ... ; c = code"<open term>".

  • Splitting the basic tutorial in two: there should be a basic tutorial using simple Code[T] types and cross-quotation references, which are now supported, and a tutorial for advanced users that demonstrates the OpenCode[T,C] type and its interaction with path-dependent Variable[T]#Ctx types.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions