Stream: beginners

Topic: ✔ Exposing tagged union variants


view this post on Zulip Aaron White (Jun 07 2024 at 01:58):

I'm too Elm pilled or something, here's what I'm trying todo:

One file (Tensor) looks like:

module [
  Number,
  Expression,
]

import Math

# In order to control the precision of our calculations,
# I'm pinning our underlying data type here
Number: F64

Expression a: [
  Value(Number, a),
  Add(Expression a, Expression a, a),
  Mul(Expression a, Expression a, a),
  Div(Expression a, Expression a, a),
  Pow(Expression a, Number, a), # For now, limit the power to a constant
  Tanh(Expression a, a),
  # Tensor([Expression a], a)
]

and in Neron.roc, I want effectively:

module [
  Neuron
]

import Tensor

Neuron a : {
  weights: List (Value(Number, a)),
  bias: a
}

but the compiler doesn't like Value appearing here (Value being a variant in Expression a in the first file). Now, in Elm I'd "crack open" the union - but AFAICT, not an option here- what is the proposed pattern?

Note: I find the compiler error messages around mis-matched tag usage very unwieldy, so my preference is to carefully pin stuff down apriori as much as I can

Any advice appreciated

view this post on Zulip Brendan Hansknecht (Jun 07 2024 at 01:59):

Value is supposed to be a tag?

view this post on Zulip Brendan Hansknecht (Jun 07 2024 at 01:59):

Oh, I think you want that to be expression

view this post on Zulip Brendan Hansknecht (Jun 07 2024 at 02:00):

Cause expression is the type

view this post on Zulip Brendan Hansknecht (Jun 07 2024 at 02:00):

Value isn't a type

view this post on Zulip Brendan Hansknecht (Jun 07 2024 at 02:00):

It's a specific tag

view this post on Zulip Aaron White (Jun 07 2024 at 02:01):

doh :man_facepalming: yes- you're right.

In this case, I _only_ want Value here (For now)

So I can pull Value out of expression- how can I create a shared 'tag' so to speak, or do I just do Value a: (Number, a) first, and then inside Expression ValueCon(Value a)?

view this post on Zulip Brendan Hansknecht (Jun 07 2024 at 02:01):

That would work

view this post on Zulip Aaron White (Jun 07 2024 at 02:02):

gracias, señor, ty for catching my stupid oversight :pray:

view this post on Zulip Notification Bot (Jun 07 2024 at 02:05):

Aaron White has marked this topic as resolved.


Last updated: Jul 06 2025 at 12:14 UTC