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

Define curried data constructor via Quark.Partial.defpartial #47

Merged
merged 3 commits into from
Mar 15, 2021

Conversation

toraritte
Copy link
Contributor

@toraritte toraritte commented Mar 11, 2019

(For issue #45)

defpartial/2 is called with args_without_defaults because defpartial/2 is implemented using defcurry/2 which would pass args with defaults to an anonymous function, and result in:

== Compilation error in file lib/algae/tree/rose.ex ==
** (CompileError) lib/algae/tree/rose.ex:34: anonymous functions cannot have optional ar
guments
    (stdlib) lists.erl:1354: :lists.mapfoldl/3
    (elixir) src/elixir_fn.erl:19: :elixir_fn.expand/3
    lib/algae/tree/rose.ex:34: (module)

On the other hand, it doesn't seem to be logical to have defaults when currying anyway:

defmodule Person do
  defdata do
    name :: string
    age  :: integer
  end
end

Person.new_partial.("lofa")

I would expect the last expression to return a function instead of %Person{name: "lofa", age: 0}.

edit: Only modified the def data_ast(lines, ...) clause in internal.ex to wait for feedback.

`defpartial/2`   is   called    with   `args_without_defaults`   because
`defpartial/2` is  implemented using `defcurry/2` which  would pass args
with defaults to an anonymous function, but:

```elixir
== Compilation error in file lib/algae/tree/rose.ex ==
** (CompileError) lib/algae/tree/rose.ex:34: anonymous functions cannot have optional ar
guments
    (stdlib) lists.erl:1354: :lists.mapfoldl/3
    (elixir) src/elixir_fn.erl:19: :elixir_fn.expand/3
    lib/algae/tree/rose.ex:34: (module)
```

On the other hand,  it doesn't seem to be logical  to have defaults when
currying anyway:

```elixir
defmodule Person do
  defdata do
    name :: string
    age  :: integer
  end
end

Person.new_partial.("lofa")
```

I  would expect  the last  expression to  return a  function instead  of
`%Person{name: "lofa", age: 0}`.
@toraritte toraritte changed the title Define curried data constructor via Quark.Partial.defpartial (#45) Define curried data constructor via Quark.Partial.defpartial Mar 11, 2019
Base automatically changed from master to main March 9, 2021 01:23
@expede
Copy link
Member

expede commented Mar 14, 2021

Yeah, that's super cool 👍 Just doing some maintenance, and will try to get this in shortly

@expede expede merged commit 91ad164 into witchcrafters:main Mar 15, 2021
@toraritte
Copy link
Contributor Author

Thanks a lot for this project and for all your hard work!

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

Successfully merging this pull request may close these issues.

2 participants