-
Notifications
You must be signed in to change notification settings - Fork 10
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
A small request for an idea #4
Comments
That is already what |
First, thanks for writing in, @walkr 😄 I agree with @OvermindDL1. Further, at the controller level, you probably want to actually blow up. Plug will then take the thrown exception, and stick it in an ErrorView of whatever As a total aside, and for the fun thought experiment: could you use the approach that you mentioned?
Sure, you could use a monad to achieve something like the flow that you're describing above. You might even be able to do some neat stuff with applicatives to test for multiple errors in parallel. I personally would find that linear sequence of You're essentially trying to wrap things in a specialized |
Thank you @expede and @OvermindDL1 for your replies. They made me aware of some new things. I was actually reading a cool post about functors, applicative and monads and I really liked one example they gave: In a procedural language one would do write something along the lines of: post = Post.find_by_id(1)
if post
return post.title
else
return nil whereas in a functional language, say Haskell, one would employ fmap (getPostTitle) (findPost 1) I personally like the second approach much better. Anyway, enough with the short rant. I will explore further these interesting concepts and try to apply some to the world of Elixir, where it makes sense. |
@walkr The stock elixir'ish way of your example would be more like this: 1
|> Post.find_by_id()
|> Post.get_title() If you handle the nil case internally via pattern matching, but even not doing that it is easy to 'fix that up' via a new call. :-) |
Gonna write another wall of text to address a few points that you brought up that have been on my mind. This gets to be the forum for it, I guess 😛 Sorry for the long read! @walkr yes, absolutely, I hear what you're saying. Haskell is by far my favourite language (though Idris is also pretty exciting), and I'm on a bit of crusade to make it possible to be more Haskell-y in Elixir (see more below).
One thing to note is that while Elixir is a functional language, it's not based around stricter algebras the way the ML family (ML, Haskell, OCaml, Idris) are. You also wouldn't use a That said, the Haskell approach is one that I enjoy greatly! Again, you absolutely can wrap everything in
The libraries that I alluded to in a previous comment (Quark, Algae, Witchcraft) are part of my attempt to write essentially "Elixirz" (like "Scalaz" and "Swiftz"). Elixir doesn't even have the basic combinator out of the box! No Once the 1.0s of |
Long reads are awesome! Plus if you've seen my posts on the elixirforums I write small novels quite routinely. ^.^
I'm more of an OCaml'er instead of a Haskell'er, I question a few more design decisions in Haskell than I do in OCaml, plus I like 50 source files compiling to be faster code than haskell's in 2 seconds instead of compiling 50 source files in haskell in 5 minutes. ^.^
Oh I am so looking forward, I think I use all of your Elixir libraries. ^.^
My free time is pretty low so unless work is paying for it... But if I can then I will. :-) |
@OvermindDL1 Yes, pattern matching is really great. I think I'm not using it frequently enough. (: Thanks for laying down your thoughts @expede and injecting some clarity into the conversation.
I have my hands in too many things right now. I don't think I have enough time to commit to something new. I will definitely keep an eye on it, and contribute if things change on my end.
Regarding this, I think it's also important to show people what advantages exists writing code a certain way vs another way; pragmatism not just style. And thank you both for being part of this conversation. That's really cool! |
I'm quite a fan of implicit modules and effect systems of the MC-OCaml world personally. (Implicit) Modules are more powerful than typeclasses (can do everything typeclasses can and more) while being significantly easier/faster to compile. :-) And the new Effect system coming in OCaml is just amazing. ^.^ |
Hello,
I just discovered
exceptional
and I see you're trying to introduce a few ideas from Haskell to Elixir, which is nice. With that given said, I was wondering if you could give me a few ideas on something I'm trying to accomplish.I'm currently working with Phoenix and I was thinking about creating a library that will allow me to write my controllers using the following flow:
The main reason I want to do this is because it improves readability, and allows one to think about the flow as a series of linear transformations.
What do you think could be a good approach? My intuition tells me a monad would do the trick, but I must admit, I'm not extremely familiar with monads, monoids and the likes. So I'm still exploring possible solutions, and also learning. (:
Thank you!
The text was updated successfully, but these errors were encountered: