Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "monad"
-
Only one sticker.
I go door-to-door every Sunday, "Excuse me dear sir/madam, do you have a moment to talk about our lord and savior Haskell?".
Most people slam the door shut in my face, but every lost family I convert to the way of the monad is worth it.
Even if they don't believe in the same deity, even if they express their love for the divine through something as misguided as Typescript or Swift or whatever, as long as they embrace the truth of strong types and composable code, as long as they at least read the gospel of the functional style once in their lives, have one enlightened moment where they see the glory of morphisms, it's all good.34 -
One of the biggest barriers to the wide(r) scale adoption of functional programming languages like Haskell, F#, and Scala is how snooty and condescending your average FP developer is. And beginner-unfriendly.
Ask them a question about an intermediate topic (in my case, the Free monad) you're likely to get a whole torrent of category theoretic rubbish in return.
This is a common pattern I see when "experts" answer questions.
Now, it didn't bother me much because I've studied a fair amount of category theory and can usually follow such answers, but, for the sake of the general case, I'd like to shove these rules into the heads of everyone writing an answer to a question (not just FP):
1. If you can't illustrate a concept clearly without going into verbal diarrhoea with phrases like "monad homomorphism" and "just a monoid in the category of endofunctors" then you clearly haven't understood it properly (unless, of course, the answer absolutely requires it). An answer is not the place to show off your knowledge of a topic.
2. Please remember that everyone was a beginner at some point. Including you. Understand that some concepts can be extremely frustrating at first and yet incredibly simple after you grok them (eg. monads).
3. If the person asking the question is a beginner, using complex concepts in an answer just because it's a more "elegant" way to explain it doesn't really help them. They are more likely to get confused and drop the topic.
(Kudos to those people who give highly relevant, insightful, simple, and intuitive answers, you guys are the best).2 -
I found this on a wiki with Haskell Humor... it's interesting...
How to Shoot Your Self in the Foot With Haskell: Putting the unsafe in unsafePerformIO!
You shoot the gun, but the bullet gets trapped in the IO monad.
Couldn't match expected type 'Deer' against inferred type 'Foot'.
While compiling your program the compiler produces a type error long enough to overflow a kernel buffer, overwrite the trigger control register and shoot you in the foot.
After trying to decipher the type errors from the compiler, your head explodes.
After you've finally found a way to circumvent the type system and shoot yourself in the foot, Oleg appears out of nothing and shoots you in the foot for coming up with it before him.
You shoot the gun but nothing happens (Haskell is pure, after all).
Your foot is fine, until you try to walk on it, at which point it becomes mangled.
You have a shootFoot function which you've proven correct. QuickCheck validates it for arbitrary you-like values. It will be evaluated only when you end up at the hospital. You hope this doesn't come to pass, as it actually returns a bullet-ridden copy of yourself and you don't want to be garbage-collected.
foreign import ccall "shootparts.h shootfoot" shoot_foot :: Gun -> Programmer -> IO ()
shootSelfInFoot = unsafePerformIO . shoot . foot $ self -- Shoot self in foot 0 or more times depending on evaluation order
No instance for (Target Foot)
arising from use of `shoot' at SelfInflictedInjury.hs:1:0
Possible fix: add an instance declaration for (Target Foot)
In the expression: shoot foot
You go to shoot yourself in the foot but the bullet is in the ST monad and the gun is in the IO monad, so you can't.
You ask Haskell to shoot you in the foot but by the rules of lazy evaluation you don't need the result yet so it doesn't happen.
You decide to shoot yourself in the foot but get distracted devising a ballistics algebra and wondering if you can do the calculations in the type system.
You want to shoot yourself in the foot but realize there is no Gun datatype so use Arrows instead.
You shoot in the direction of your foot, but since you are inside the STM monad you can just retry until you figure out what to do.
You shoot yourself in the foot, but you are perfectly fine as long you just don't evaluate the foot.
You shoot yourself in the foot, but nothing happens unless you start walking.
Don't forget about memory consumption! If you don't look, the bullet causes heap overflow. If you look, the bullet causes stack overflow.
You *appear* to have deliberately shot yourself in the foot, and yet your program actually runs perfectly OK due to lazy evaluation. (So long as you remember to not look at your foot...)
You aim the gun at your foot, pull the trigger and remove the clip. When you look at your undamaged foot, the hammer clicks on an empty barrel.1 -
yeah I am a software engineer.
yea I am a programmer too.
yeah I am behind my laptop all the time..
but no I don't want to fix your computer.
I have no interest in changing your windows, installing antivirus on your pc and so on..
just understand it , God damn these shit people :( -
On C++ forum and see reference to Type Erasure (TE). Search around, some Java shit bleeding into other programming languages. Finally find an article that not only explains what TE is, but why you would use it in C++. ITS JUST FUCKING DUCK TYPING. Please stop using stupid names for stuff. You don't sound smarter. You sound like an asshole. Anyway, thinking about it does make sense to call it Type Erasure, but I still think it sounds pretentious. Cool concept, stupid name. Will continue to confuse people saying: "oh, you mean duck typing?"
Cool article:
https://davekilian.com/cpp-type-era...
The wikipedia article about TE doesn't explain shit about why you would even use it. Just repeats the same word salad of words I first saw about TE. I get that its jargon, but from the outside it just sounds like bullshit. I have never heard anyone I work with spew out shit like that. Even the ones with masters degrees in computer science.
I am not even sure I want to learn more about CS than what keeps me employed. I don't want to sound like this when I talk. I have already said shit in meetings about modern C++ that has colleagues (other sparkies, and some CS people) wondering what I was smoking. It wasn't even that jargony.
Don't mind me, just a sparky starting to understand why the CS world is so fucked. Maybe its just academia I can't stand. I dunno.
I should ask in a meeting if someone can define a monad for me.21 -
One advantage of being reasonably proficient with Haskell is being able to very quickly create maintainable programs, often without needing to write extensive documentation.
One disadvantage of having Haskell as a favourite programming language is sometimes looking like a pretentious ass.
But just read the type definition and think for once, idiot. How could "Monad m => (a1 -> a2 -> a3 -> a4 -> r) -> m a1 -> m a2 -> m a3 -> m a4 -> m r" confuse even a beginner to computer programming, nonetheless Haskell?3 -
Sometimes my hatred for code is so.. overwhelming that I think I need a sabbatical or should even stop altogether.
Let's face it. All code sucks. Just on different levels.
Want to go all bare metal? Love low level bit fiddling. Well, have fun searching for concurrency, memory corruption bugs. Still feel confident? Get ulcers from large C/C++ code base already in production, where something in the shared memory, function pointer magic is not totally right?
So you strive for more clean abstractions, fancy the high level stuff? Well, can you make sense of gcc's template error messages, are you ready for the monad, leaving behind the mundane everyday programmers, who still wonders about the scope of x and xs?
Wherever you go. Isn't it a stinking shit pile of entropy, arbitrary human made conventions? You're just getting more familiar with them, so you don't question them, they become your second skin, you become proficient - congrats you're a member of the 1337.7 -
So a monad is basically a specialized object for converting to and from a datatype. So FP has specialized objects. Monad marries OO with FP in that sense. In C++ I would do this pattern with a class because it makes sense to encapsulate it there. Or at least a namespace.
Change my mind.
https://en.wikipedia.org/wiki/...7 -
Fucking IT bloggers be telling you about how to deploy scalable hype meta monad 420 doritos bacon containers. Forget those hipsters.
The only developer blog you need is ACM Queue. -
It's nice that more and more languages are introducing async/await syntax, but by the example of Rust in particular I'm starting to wonder why we don't instead introduce this syntax for monads in general?
We could have a keyword (say, `bind`) which unwraps a value from any monad provided that the return value of the function is wrapped in the same monad. The ? operator does something a little similar, and I'll be intrigued whether it can actually be implemented for monads other than Result and Option once GATs are stabilized. In particular in the case of Rust, it would be possible to create a reference counting monad for heap-bound management of objects derived from references.9 -
So I recently finished a full stack web development bootcamp and I realized something at the end of it... I suck at and consequently hate Javascript... Any idea on how to change that? Whenever I see a task related to JS my first response is NOPE.4
-
After many false starts, I think I may finally be understanding Haskell to the point I could actually be productive in it. It's fun to be interested and motivated in a side project solely because of the language being used to write it!
-
ISO floating point numbers are essentially wrapped in a hardware-level monad because the normal meaningful values aren't closed over basic arithmetic so conceptually wrapping everything in Maybe using the 'infectious sentinel value' NaN leads to substantial speedups.
With this in mind, I think high-level languages that have a Maybe should use those and have the language-type float refer to a floating point that isn't NaN.2 -
Just gonna see what this functional fuss is all about.
Two weeks later: Uses state, mutation, monad every other sentence. -
Not being able to lol at "Monad is a monoid in the category of endofunctors." joke even after several readings of articles/guides online.
-
I could really do with HKT support in Rust right now. I need to somehow convert a
Marc<Task<Output = T>> into a
Task<Output = Marc<T>> where Marc is a Mappable Atomic Reference Counter from the mappable_rc crate. Nothing technically challenging in the whole operation, it's just not supported by the type system without those two types knowing about each other.