Zulip Chat Archive

Stream: general

Topic: metaprogramming twitch stream


Quinn (Aug 24 2024 at 18:49):

https://www.twitch.tv/quinn_dougherty project: jsonable ASTs of proofs for machine learning reasons

Quinn (Aug 24 2024 at 18:49):

going live in just a sec

Adam Topaz (Aug 24 2024 at 19:02):

Have you seen https://github.com/andrejbauer/lean2sexp ?

Quinn (Aug 24 2024 at 19:18):

no, thanks!!!!

Adam Topaz (Aug 24 2024 at 19:28):

I dont think there anything there that converts sexprs to json, but that should be really easy (it may even be possible to automatically derive a ToJson instance)

Quinn (Aug 24 2024 at 19:46):

dude this rocks so hard. i had no idea. thanks so much

Quinn (Aug 24 2024 at 19:49):

#synth ToJson Sexp does fail, but i can hand roll it

Adam Topaz (Aug 24 2024 at 20:12):

You can try to derive it

Quinn (Aug 24 2024 at 20:13):

what's the difference between derive and #synth? i thougth they were working with the same underlying capacties

Quinn (Aug 24 2024 at 20:14):

huh. you're right. going into source and adding deriving ToJson worked, even tho synth failed and when i tried to handroll it i thought i'd have to bypass termination checker or something

Adam Topaz (Aug 24 2024 at 20:15):

import Lean

inductive Sexp : Type
| atom : String  Sexp
| string : String  Sexp
| integer : Int  Sexp
| double : Float  Sexp
| cons : List Sexp  Sexp
deriving Inhabited, Lean.ToJson

#synth Lean.ToJson Sexp

Adam Topaz (Aug 24 2024 at 20:15):

you need to tell lean to explicitly derive the instance. #synth is for typeclass instances that already exist.

Quinn (Aug 24 2024 at 20:16):

oh. i was totally wrong about what synth is then

Julian Berman (Aug 24 2024 at 20:19):

I'm not sure this is correct (so I'll say it so someone points out a counterexample) but I don't think #foo commands ever have side effects (so it wouldn't create an instance)

Adam Topaz (Aug 24 2024 at 20:19):

#foo commands could have side effects, but in practice they don't

Julian Berman (Aug 24 2024 at 20:19):

Yeah I meant stylistically to be clear.

Quinn (Aug 24 2024 at 20:19):

i basically thought it checked if the synthesis was possible, i didn't think it was actually creating it

Adam Topaz (Aug 24 2024 at 20:20):

deriving does something different.

Adam Topaz (Aug 24 2024 at 20:20):

synth just uses the typeclass system, but deriving uses custom handlers to derive instances

Patrick Massot (Aug 24 2024 at 20:20):

Note that you can use deriving in another file, you don't have to edit the original definition.

Quinn (Aug 24 2024 at 20:21):

That's a great note as well!

Adam Topaz (Aug 24 2024 at 20:21):

Right (but I always forget the magic spell for this)

Quinn (Aug 24 2024 at 20:21):

What does that look like?

Adam Topaz (Aug 24 2024 at 20:21):

I thought it was deriving instance Lean.ToJson for Sexp or something like that?

Patrick Massot (Aug 24 2024 at 20:22):

Yes

Adam Topaz (Aug 24 2024 at 20:36):

@Quinn I'm watching your stream: you probably want IO.FS.Handle.putStrLn together with Json.compress (or just toString)

Adam Topaz (Aug 24 2024 at 20:37):

compress will make it into a single line

Adam Topaz (Aug 24 2024 at 20:37):

toString usage is toString j for j : Json

Adam Topaz (Aug 24 2024 at 20:42):

you can a moduledata from an olean, or from the environment header which is part of an environment


Last updated: May 02 2025 at 03:31 UTC