Zulip Chat Archive

Stream: lean4

Topic: Where are double colons used?


Shreyas Srinivas (Jul 17 2023 at 13:14):

A little snippet from #tpil4 shows that when declaring a structure one uses double colons if one wants to explicitly declare its fields as part of a single constructor like mk:

namespace Hidden
structure Prod (α : Type u) (β : Type v) where
  mk :: (fst : α) (snd : β)
end Hidden

Is there any other place where the :: is used for type annotations?

Kyle Miller (Jul 17 2023 at 13:16):

For what it's worth, you can put this mk :: in a few places that let you use the parenthesis-less notation for explicit fields.

structure Prod (α : Type u) (β : Type v) where mk ::
  fst : α
  snd : β
structure Prod (α : Type u) (β : Type v) where
  mk ::
  fst : α
  snd : β

Kyle Miller (Jul 17 2023 at 13:18):

This use of :: is unique to structure commands

Kyle Miller (Jul 17 2023 at 13:19):

In Lean.Parser.Command you can find

def «structure»          := leading_parser
    (structureTk <|> classTk) >> declId >>
    ppIndent (many (ppSpace >> Term.bracketedBinder) >> optional «extends» >> Term.optType) >>
    optional ((symbol " := " <|> " where ") >> optional structCtor >> structFields) >>
    optDeriving

where

def structCtor           := leading_parser
  atomic (ppIndent (declModifiers true >> ident >> " :: "))

Kyle Miller (Jul 17 2023 at 13:23):

(I didn't know there was a declModifiers in there before the ident. That means that you can for example put protect before mk to protect the constructor.)

Shreyas Srinivas (Jul 17 2023 at 13:50):

okay, so this is a one-off case. Thanks :). I have never seen :: used in lean anywhere , except when reading #tpil4

Mario Carneiro (Jul 17 2023 at 16:43):

The more common use is for the "cons" operation on lists

Shreyas Srinivas (Jul 17 2023 at 17:31):

Ah yes. I should have clarified that I was thinking about type declarations and annotations


Last updated: Dec 20 2023 at 11:08 UTC