5 ms·
Haskell - You try to shoot yourself in the foot, but instead, a new foot appears in front of you that is identical to your own except that it has a bullet in it
by DanWaterworth 13y ago
Haskell - You try to shoot yourself in the foot, but instead, a new foot appears in front of you that is identical to your own except that it has a bullet in it. Oh, and it's wrapped inside a burrito for some reason...
- joejohnson 13y agogun `shoot` foot But there’s a side effect, so it doesn’t work. Try to use the state monad… get confused, so you write your own shooting monad, and then come up with this code: gun >= id foot but this puts your gun in your foot. Then you write your data types data Space = Empty | Gun| Foot deriving (Show, Eq, Ord) –if you’re right-handed, this code should work shootFoot = foldr (shoot bullet) Empty $ enumFromTo Gun Foot –For southpaws foldl’ (shoot bullet) Empty $ enumFromTo gun foot
- jerf 13y agoExcellent. I also would have accepted Violence.hs:5:35: No instance for (Shootable BodyPart) arising from a use of 'shoot' Possible fix: add an instance declaration for (Shootable BodyPart) In the expression: shoot $ user ^. foot In an equation for 'violence': violence user = shoot $ user ^. foot
- DanWaterworth 13y agoYou should abstract this; you realize bullets are group actions on the set of feet, right? Edit: Sorry, not group actions, monoid actions. Group actions would mean there was some kind of inverse bullet. Also note that bullets aren't commutative.
- rev_null 13y agoThe new foot only appears if you try to do something with it.
- mercurial 13y agoYou try to shoot yourself in the foot, but you realize the bullets are of the wrong type. After sawing the bullets to the right size, you attempt to lift your gun, but it takes too much space and blows up.
- tel 13y agoHaskell—after spending a great deal of effort setting up various layers of foot-shooting-proof prophylactics you find yourself in a situation where the only reasonable way to start walking is to go ahead and shoot yourself in the foot anyway. You do so and are able to basically walk except somewhat awkwardly thanks to your now bleeding foot. Then you go online and are helpfully told that what you really needed was a an abstract shoe, that bleeding feet are prone to infection and impurities, and if you had only read this one research paper there's a 2-liner in there showing you how to program Usain Bolt with wings.