Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbol type (evaluated to itself, e.g. for type expressions) #1277

Open
andychu opened this issue Aug 14, 2022 · 4 comments
Open

Symbol type (evaluated to itself, e.g. for type expressions) #1277

andychu opened this issue Aug 14, 2022 · 4 comments

Comments

@andychu
Copy link
Contributor

andychu commented Aug 14, 2022

Should behave something like Python

>>> from typing import Dict
>>> Dict
typing.Dict


>>> Dict[int,int]
typing.Dict[int, int]
>>> 

How to create it?

const Dict = Symbol() 

# or

const Dict = Symbol('Dict')

Or a builtin can create it:

define-symbols Dict Str Int Optional Mutated

Hay

Func concat {
  param left (List[Str])
  param right (List[Str])
  returns result (List[Str])
}

Is %foo a Symbol or a string? It can be an auto-created symbol Symbol('foo')

Does %foo == 'foo' ? Probably not

But Dict == Dict, yes

Identity is an interned strings? Plus children? Might relate to Hay tree as well


Restrict number of children like Python does? Dict[int] is invalid. Probably not? This can be done by the consumer of the structure


How to serialize it? As JSON lists? I guess that works.

Dict[Str, Int] ->

["Dict", ["Str", "Int"]]   # if there are no children, it's a string

Dict[Str, List[Int]] ->

["Dict", ["Str", ["List", ["Int"]]]
@andychu
Copy link
Contributor Author

andychu commented Aug 14, 2022

@andychu
Copy link
Contributor Author

andychu commented Aug 14, 2022

Similar to Wolfram m-expressions: https://en.wikipedia.org/wiki/M-expression

I also wonder if we want Func[Str, Str => Int, Int] -- I think the grammar can handle that

@andychu
Copy link
Contributor Author

andychu commented Aug 14, 2022

Hm you can also makes slices.

For QTT[name: Str, age: Int]

Or does it need to be:

QTT['name': Str, 'age': Int] ?

Or

QTT[Col['name', Str], Col['age', Int]]

>>> Dict[int, int:int]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/typing.py", line 682, in inner
    return func(*args, **kwds)
  File "/usr/lib/python3.6/typing.py", line 1107, in __getitem__
    params = tuple(_type_check(p, msg) for p in params)
  File "/usr/lib/python3.6/typing.py", line 1107, in <genexpr>
    params = tuple(_type_check(p, msg) for p in params)
  File "/usr/lib/python3.6/typing.py", line 374, in _type_check
    raise TypeError(msg + " Got %.100r." % (arg,))
TypeError: Parameters to generic types must be types. Got slice(<class 'int'>, <class 'int'>, None).
>>> 

@andychu
Copy link
Contributor Author

andychu commented Sep 28, 2022

Useful in Hay, but also proc param signatures ?

https://oilshell.zulipchat.com/#narrow/stream/325160-oil-discuss-public/topic/Proc.20Param.20Passing.20-.20Brainstorming

Although I guess those can be arbitary expressions that are unevaluated

So they don't even need to be symbol values? Just expressions


Only needed on the RHS for Hay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant