!amEFGYrRomMpJtiMDK:matrix.org

Scala Metaprogramming

908 Members
4 Servers

Load older messages


SenderMessageTime
24 Jan 2023
@_discord_231350810565410817:t2bot.ioragnar#4252 Basically quasiquotes and the Expr API try to guarantee hygiene if I understand correctly … which they do by not allowing you to interact with names much. 10:47:37
@_discord_231350810565410817:t2bot.ioragnar#4252 I think there is ValDef.let(owner, expressions) { defs => where defs then is the list of references to each of the expressions. 10:48:55
@_discord_231350810565410817:t2bot.ioragnar#4252 * I there is ValDef.let(owner, expressions) { defs => where defs then is the list of references to each of the expressions. 10:49:00
@_discord_231350810565410817:t2bot.ioragnar#4252 But maybe there is something easier for you to use … 10:49:06
@_discord_192322936219238400:t2bot.ioAly
(0 == (
  ((Int @ "a") == (Int @ "b")) match {
    case true => -1
    case false =>
      IndexWhere[
        (Int @ "b") *: EmptyTuple,
        [Y] => (Int @ "a") == Y,
        S[-1]
      ]
  }
)) match {
  case true =>
    (Int @ "a" *:
      FilterOnIndex[
        (Int @ "b") *: EmptyTuple,
        [X, I] =>
          (I ==
            IndexWhere[
              (Int @ "a") *: (Int @ "b") *: EmptyTuple,
              [Y] => X == Y,
              -1
            ]
          ),
        S[0]
      ]
    )
  case false =>
    FilterOnIndex[
      (Int @ "b" *: EmptyTuple),
      [X, I] =>
        (I == 
          IndexWhere[
            (Int @ "a") *: (Int @ "b") *: EmptyTuple,
            [Y] => X == Y,
            -1
          ]
        ),
      S[0]
    ]
}

go nuts :)
10:52:41
@_discord_192322936219238400:t2bot.ioAly (I have to assume those are meant to be [X, I] =>> and not [X, I] =>?) 10:53:26
@_discord_266680529020125185:t2bot.ioAdam ឵឵ Yeah that's a bug in compiler viz 11:06:31
@_discord_266680529020125185:t2bot.ioAdam ឵឵ Ha it just can't compare non-primitive types with == 11:07:11
@_discord_266680529020125185:t2bot.ioAdam ឵឵ Wait what 11:08:42
@_discord_266680529020125185:t2bot.ioAdam ឵឵
be.adamv.momentum.concrete.Node$package.FilterOnIndex[
            scala.Tuple$package.EmptyTuple,
            [X >: scala.Nothing <: scala.Any, I >: scala.Nothing <: scala.Int] =>>
              scala.compiletime.ops.any.==[I,
                be.adamv.momentum.concrete.Node$package.IndexWhere[
                  scala.*:[be.adamv.momentum.Tags.Value[scala.Int, "a"],
                    scala.*:[be.adamv.momentum.Tags.Value[scala.Int, "b"],
                      scala.*:[be.adamv.momentum.Tags.Value[scala.Int, "c"],
                        scala.Tuple$package.EmptyTuple]]],
                  [Y >: scala.Nothing <: scala.Any] =>>
                    scala.compiletime.ops.any.==[
                      be.adamv.momentum.concrete.Node$package.TagOf[X],
                      be.adamv.momentum.concrete.Node$package.TagOf[Y]], 0]], scala.compiletime.ops.int.S[2]]

does reduce on its own, but not as an element of a tuple
11:09:28
@_discord_266680529020125185:t2bot.ioAdam ឵឵ *
be.adamv.momentum.concrete.Node$package.FilterOnIndex[
            scala.Tuple$package.EmptyTuple,
            [X >: scala.Nothing <: scala.Any, I >: scala.Nothing <: scala.Int] =>>
              scala.compiletime.ops.any.==[I,
                be.adamv.momentum.concrete.Node$package.IndexWhere[
                  scala.*:[be.adamv.momentum.Tags.Value[scala.Int, "a"],
                    scala.*:[be.adamv.momentum.Tags.Value[scala.Int, "b"],
                      scala.*:[be.adamv.momentum.Tags.Value[scala.Int, "c"],
                        scala.Tuple$package.EmptyTuple]]],
                  [Y >: scala.Nothing <: scala.Any] =>>
                    scala.compiletime.ops.any.==[
                      be.adamv.momentum.concrete.Node$package.TagOf[X],
                      be.adamv.momentum.concrete.Node$package.TagOf[Y]], 0]], scala.compiletime.ops.int.S[2]]

does reduce (to EmptyTuple) on its own, but not as an element of a tuple
11:09:46
@_discord_266680529020125185:t2bot.ioAdam ឵឵ What did I decide to do dedup on the type level 🙈 11:11:06
@_discord_266680529020125185:t2bot.ioAdam ឵឵ * Why did I decide to do dedup on the type level 🙈 11:13:19
@_discord_224135672200429570:t2bot.ioDavid H. Will give that a try, thanks 11:18:51
@_discord_387435475142705152:t2bot.iozebos#7602 changed their profile picture.19:57:21
@_discord_266680529020125185:t2bot.ioAdam ឵឵ Yeah minimizing this for a bug report is no fun 20:18:32
@_discord_266680529020125185:t2bot.ioAdam ឵឵ How it started
https://github.com/Adam-Vandervorst/Momentum/blob/fa2f6a45508ae016706c364ba45e77d3c806ce57/src/test/scala/concrete/Node.scala#L79
How it is going
https://github.com/Adam-Vandervorst/Momentum/blob/05c47167093db409ea41dafabfd37465a0c7132c/src/test/scala/concrete/Node.scala#L51
23:31:15
@_discord_266680529020125185:t2bot.ioAdam ឵឵ Got to love type level programming (when it works) 23:31:41
@_discord_266680529020125185:t2bot.ioAdam ឵឵ Note that
ls.apply("a" -> 1, "b" -> 2, "c" -> 3)
looks like it just constructing a map, but it's actually just feeding in 1, 2, 3, and the keys are typelevel
23:32:39
@_discord_231350810565410817:t2bot.ioragnar#4252 I am just happy that I am not the only one with code without any documentation just randomly put on the internet to be able to link excerpts I am excited about to other people 👍 23:38:42
26 Jan 2023
@_discord_1006368317117841469:t2bot.iojarek_rozanski joined the room.00:02:09
@_discord_597155328022413313:t2bot.ioebo I actually also gave up on my type class derivation automation I showed you. For whatever reason, it wouldn't automatically derive enum types!

I ended up just using the more straight forward cookie cutter approach you find all over. e.g.:

https://medium.com/riskified-technology/type-class-derivation-in-scala-3-ba3c7c41d3ef

A lot more code, but also much simpler APIs and seems to work for more edge cases
01:32:04
@_discord_597155328022413313:t2bot.ioebo * So I ended up giving up on my type class derivation automation I showed you. For whatever reason, it wouldn't automatically derive enum types!

I ended up just using the more straight forward cookie cutter approach you find all over. e.g.:

https://medium.com/riskified-technology/type-class-derivation-in-scala-3-ba3c7c41d3ef

A lot more code, but also much simpler APIs and seems to work for more edge cases
01:32:29
@_discord_403609872123428864:t2bot.ioIl_totore#9133 Well actually mirror is as far as I know the recommended way to do typeclass derivation 06:44:48
@_discord_231350810565410817:t2bot.ioragnar#4252
For whatever reason, it wouldn't automatically derive enum types!
The code I remember discussing did only use Mirror.ProductOf, so it would not be too surprising that it does not cover enums (which are sum types not product types).
But if stuff works now that is great!
11:07:31
@_discord_597155328022413313:t2bot.ioebo ah gotcha, it's only enum case that is product type - not the enum itself. Makes sense. 13:36:08
@_discord_468568169590554625:t2bot.iojdelman joined the room.17:11:42
27 Jan 2023
@_discord_754506755307733082:t2bot.iobeees joined the room.01:41:29
@_discord_989449122090197005:t2bot.iomichal.przysucha joined the room.12:40:10
@_discord_167571481432162305:t2bot.iopolux joined the room.16:14:30

There are no newer messages yet.


Back to Room List