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

Runtime issue in compiled code #32

Open
nsadeh opened this issue Jul 20, 2022 · 0 comments
Open

Runtime issue in compiled code #32

nsadeh opened this issue Jul 20, 2022 · 0 comments

Comments

@nsadeh
Copy link

nsadeh commented Jul 20, 2022

This is a duplicate of issue #3 , where passing an Html.Attributes.class instance to an svg function results in a runtime error, even though the code compiles just fine.

Example:

svg [ class "fill-green-400" ] [ Icons.Outlined.check 20 Neutral ] 

this compiles fine, but on runtime, we get an infinite loop of

Cannot set property className of #<SVGElement> which only has a getter

I know (through asking in Elm Slack - it took away about an hour of my time), that I need to pass in Svg.Attributes.class, but this is still an important bug to fix in my opinion. Here are two reasons why:

  1. It breaks the core promise of Elm: I had code that compiled correctly but threw a runtime error
  2. It violates a functional contract: I had a function that promised me if I gave it an array of Html.Attribute and Svg that I would get back an Html msg without side effects. I gave it valid instances of both and saw a side effect (detailed above). This is slightly worse than public Html<M> svg(List<Html.Attribute> attributes, List<Svg> svgs) throws Exception, because at least the method signature says the that it throws.

I saw the counterargument that I should know better about the difference between SVGs and HTMLs to pass in the right class method, but I counter that I really shouldn't need to:

In strongly-typed functional programming all I need to know is the type of my inputs to know what type of output I get and whether I should expect side effects. I might need to understand the workings of the function to know what value to expect, but not what type and whether any errors or other side effects will happen. The classical example is dividing by zero, where in an imperative language it may throw and error and stop the program, but in a functional language it will return a value so regardless of whether you understand division or not you know whether the program will continue running, throw and error, and what kind of value it will return.

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

No branches or pull requests

1 participant