Giter Club home page Giter Club logo

Comments (19)

brprice avatar brprice commented on May 25, 2024 1

How do we handle constructors?
The two options are

  • Traditional non-bidirectional style: constructors are terms in-and-of themselves, and are synthesisable. Thus one has Cons ∈ ∀a. a -> List a -> List a, and Cons @Int 3 ∈ List Int -> List Int.
  • Dogmatic bidirectional style: constructors must be fully applied, and are checkable (recall, bidirectional style says "constructions are checkable, eliminations are synthesisable"). Thus Cons is not well-typed on its own: in particular ∀a. a -> List a -> List a ∋ Cons is false. One instead has List Int ∋ Cons 2 Nil. To use constructors as functions, one must eta-expand thus: map (\n -> Succ n) ∈ List Nat -> List Nat. Notice that in this style constructors do not contain their parameters -- we have List Int ∋ Cons 2 Nil rather than Cons @Nat 2 (Nil @Nat). This works because we always know the exact type we are considering when looking at a constructor, and that tells us the parameters. We also can have different types having constructors with exactly the same name (in the core AST) and not worry about disambiguating them -- however this is a very minor concern for a structure editor since it is trivial to pun/disambiguate in the UI.

from primer.

brprice avatar brprice commented on May 25, 2024 1

Another definitional thing to hash out: can type constructors or value constructors be named the same thing as term definitions?

And, (https://github.com/hackworthltd/vonnegut/pull/844#discussion_r708269938) what do holes mean inside typedefs? data T = C (List ?). Should they be forbidden? It is easy to enforce this (indeed, our current frontend does), but may be awkward to change the generators used in testing to obey this.

from primer.

georgefst avatar georgefst commented on May 25, 2024 1

We should expose lettype to students, rather than having it only appear in eval mode. I think @brprice has indicated that this shouldn't be difficult, but we probably want to formalise it anyway.

from primer.

brprice avatar brprice commented on May 25, 2024 1

Do we want (and if so, in a 1.0, or sometime later) an analogue to Haskell's typeclasses, or maybe some other "get the compiler to write code for us" feature? It would be worth roughly answering this early as it will interact with other design decisions (we should avoid backing ourselves into a corner where it is hard to add this feature).

A useful (rather old) publication is Simon Peyton Jones Mark Jones Erik Meijer : Type classes: an exploration of the design space

from primer.

georgefst avatar georgefst commented on May 25, 2024 1

We have discussed several times that we eventually want to have richer patterns, in particular wildcards (necessary in practice to have pattern matching on primitives) and nested patterns.

(we don't expect this to make it in to Primer 1.0, and there's a lot more to say on the topic, but I need somewhere to link to whenever the future of patterns comes up)

from primer.

dhess avatar dhess commented on May 25, 2024

Edit I moved the contents of this comment to the OP.

from primer.

brprice avatar brprice commented on May 25, 2024

I don't know if the following would come under "typography" or "namespaces" or if it is a different suggestion.

Some languages will allow you to use the module system to distinguish local and global vars, e.g.

module Main where
foo :: Bool -> Nat
foo = ...

bar :: Char -> Nat
bar = λa . foo (a == 'x')

baz :: Bool -> Nat
baz = λfoo . Main.foo foo

where foo means "the most locally bound foo", but Main.foo means "the global foo"

from primer.

dhess avatar dhess commented on May 25, 2024

I don't know if the following would come under "typography" or "namespaces" or if it is a different suggestion.

I view this as a namespace solution.

Some languages will allow you to use the module system to distinguish local and global vars, e.g.

module Main where
foo :: Bool -> Nat
foo = ...

bar :: Char -> Nat
bar = λa . foo (a == 'x')

baz :: Bool -> Nat
baz = λfoo . Main.foo foo

where foo means "the most locally bound foo", but Main.foo means "the global foo"

Does Haskell? I've never tried to do this in the same module as where foo is defined.

from primer.

brprice avatar brprice commented on May 25, 2024

foo means "the most locally bound foo", but Main.foo means "the global foo"

Does Haskell? I've never tried to do this in the same module as where foo is defined.

Yes (at least, GHC 8.10.4)

from primer.

dhess avatar dhess commented on May 25, 2024

edit: I moved the contents of this comment to the OP.

from primer.

dhess avatar dhess commented on May 25, 2024

It might be time to put this in a Craft document, which would be easier to collaboratively edit.

from primer.

dhess avatar dhess commented on May 25, 2024

We should expose lettype to students, rather than having it only appear in eval mode. I think @brprice has indicated that this shouldn't be difficult, but we probably want to formalise it anyway.

Shower thought: exposing lettype in the language, and especially adding it to a modules-as-records implementation, means that unqualified constructor names are now potentially free variables in some scopes! Ignore this please, I'm not sure it made sense.

from primer.

dhess avatar dhess commented on May 25, 2024

We should expose lettype to students, rather than having it only appear in eval mode. I think @brprice has indicated that this shouldn't be difficult, but we probably want to formalise it anyway.

I've added this to the main list now.

from primer.

dhess avatar dhess commented on May 25, 2024

Do we want (and if so, in a 1.0, or sometime later) an analogue to Haskell's typeclasses, or maybe some other "get the compiler to write code for us" feature? It would be worth roughly answering this early as it will interact with other design decisions (we should avoid backing ourselves into a corner where it is hard to add this feature).

A useful (rather old) publication is Simon Peyton Jones Mark Jones Erik Meijer : Type classes: an exploration of the design space

I've added a note about this to the main list.

from primer.

dhess avatar dhess commented on May 25, 2024

Another definitional thing to hash out: can type constructors or value constructors be named the same thing as term definitions?

And, (hackworthltd/vonnegut#844 (comment)) what do holes mean inside typedefs? data T = C (List ?). Should they be forbidden? It is easy to enforce this (indeed, our current frontend does), but may be awkward to change the generators used in testing to obey this.

These are now captured in the main list.

from primer.

dhess avatar dhess commented on May 25, 2024

How do we handle constructors? The two options are

  • Traditional non-bidirectional style: constructors are terms in-and-of themselves, and are synthesisable. Thus one has Cons ∈ ∀a. a -> List a -> List a, and Cons @Int 3 ∈ List Int -> List Int.
  • Dogmatic bidirectional style: constructors must be fully applied, and are checkable (recall, bidirectional style says "constructions are checkable, eliminations are synthesisable"). Thus Cons is not well-typed on its own: in particular ∀a. a -> List a -> List a ∋ Cons is false. One instead has List Int ∋ Cons 2 Nil. To use constructors as functions, one must eta-expand thus: map (\n -> Succ n) ∈ List Nat -> List Nat. Notice that in this style constructors do not contain their parameters -- we have List Int ∋ Cons 2 Nil rather than Cons @Nat 2 (Nil @Nat). This works because we always know the exact type we are considering when looking at a constructor, and that tells us the parameters. We also can have different types having constructors with exactly the same name (in the core AST) and not worry about disambiguating them -- however this is a very minor concern for a structure editor since it is trivial to pun/disambiguate in the UI.

This is now addressed in the main list, and reflects our decision that they should be synthesizable.

from primer.

dhess avatar dhess commented on May 25, 2024

We have discussed several times that we eventually want to have richer patterns, in particular wildcards (necessary in practice to have pattern matching on for primitives) and nested patterns.

(we don't expect this to make it in to Primer 1.0, and there's a lot more to say on the topic, but I need somewhere to link to whenever the future of patterns comes up)

Added.

from primer.

dhess avatar dhess commented on May 25, 2024

We discussed this issue at length in our 2022-03-22 Primer definition meeting. I've updated the OP now to reflect all of our thinking as of this date.

I think it's now time to open tracking issues for each specific item in the OP, and to close this issue, as it has served its purpose.

from primer.

dhess avatar dhess commented on May 25, 2024

Each sub-issue described in the OP that has survived the "what should we include in Primer's language definition?" is now tracked by its own separate issue. Therefore, I'm now closing this issue.

from primer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.