pera
Is anyone here using Witchcraft?
I am curious because Witchcraft (and related projects like Algae) can be super useful when for example you are working with complex data structures, yet I almost never see people mentioning it in this forum which makes me wonder, why not? ![]()
For those who are not familiar with this project, here is a great introduction to it by its author:
Most Liked
dorgan
You’re already using all that stuff, what’s intimidating is that you need some background to know their formal names.
For example, say you want to perform some task in parallel, so you need to split the work, but in order to split it and make it the same as doing it serially, you need to satisfy that splitting [abc] into [ab][c] is the same as [a][bc] under the operation you want to perform. In other words, you can arbitrarily split the task and it’s not order dependent.That’s a practical application of a monoid. There’s a Rich Hickey talk about this but I can’t recall which one, either the one about transducers or the one about reducers, he mentions this property about parallelizable work and says something like “and this is a monoid” and chuckles.
Or you have stuff inside some context, like [a, b] or {:ok, a}, and you want a function that can apply a function to these wrapped values. That’s map, and the map+context is what defines a functor. If the context can be 2 values, like {:ok, a} and {:error, b}, and map takes a function for each case, then it’s a bifunctor.
If you have a wrapped value {:ok, a} and a function that takes a value a and returns {:ok, b}, applying map twice would return {:ok, {:ok, b}}, so you want a function that applies the function and unwraps the result, that’s flat_map/bind, and it’s what characterizes a monad.
Foldables are comparable to an Enum that you can reduce, and it’s why in Erlang it’s named :lists.foldl.
And so on and so forth. If you know the background for these names, then it’s simple and useful. If you don’t, then you end up implementing ad-hoc versions of them all the time.
What IS weird about them in Elixir is that they are mostly formalized with regards to functions, not data, so a lot of it is about composing functions, and more so in environments where functional composition is the only way you have to write a program(Haskell works this way). In Elixir we have higher order functions but we don’t have auto currying so it becomes weird to properly implement that programming style.
lpil
Witchcraft is a very cool library but without a static type system I personally don’t enjoy these design patterns as much as I do in languages like Haskell. I’d love to see this alongside a statically typed Elixir ![]()
al2o3cr
Seconding @hassan’s query: are there examples of this?
The examples in the documentation mostly use numbers, which are simple to use in doctests and automatically satisfy a bunch of properties - but that obscures why a user would want to distinguish between (say) a semigroup and a monoid (since numbers always have zero).
IMO the library would get more attention if it was clearer what problems it makes easier to solve - right now, it mostly seems like using Witchcraft is a way to make Elixir look more like Haskell.
Popular in Discussions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









