pera

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? :slightly_smiling_face:

For those who are not familiar with this project, here is a great introduction to it by its author:

Most Liked

dorgan

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

lpil

Creator of Gleam

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 :slight_smile:

al2o3cr

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.

Where Next?

Popular in Discussions Top

Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
mmmrrr
Just saw that dhh announced https://hotwire.dev/ Is it just me or is this essentially live view? :smiley: Although I like the “iFrame-e...
New
AstonJ
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
crabonature
I’m still quite new to Elixir. As I understand we got in Elixir “multi guards” as convention to simplify one large guard with or’s?: de...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
wmnnd
The Go vs Elixir thread got me thinking: Would it be too hard to implement a simple mechanism for creating Go-style static app binaries f...
New
pdgonzalez872
If this has been asked here before, please point me to where it was asked as I didn’t find it when I searched the forum. Maybe a mailing ...
New

Other popular topics Top

chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39523 209
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement