Hah, I just finished a semester of grading people's Haskell homework :D (was good enough at it when I took the class a year before, that they wanted to hire me for the next year)
I didn't know about it being on Foldable prior to making this comment either, but hoogle is a really nice tool for looking up documentation & sources on this sorta stuff for any package on stackage. I looked it up as I'd expect the implementation to be tail-recusrive it if was on lists.
You can even use them to finally destructure objects and dicts, although it's a little hacky:
d={'a':1,'b':2,'c':3}matchd:case{'a':1,'b':b,**rest}:passprint(b,rest)# prints 2, {"c": 3}
fromdataclassesimportdataclass@dataclassclassPoint:x:inty:intz:intp=Point(4,5,6)matchp:casePoint(4,y,z):passprint(y,z)# prints 5, 6
13
u/TwoFiveOnes Feb 02 '24
why does it need to do the recursion at III? isn't just 1 base case enough?
165
u/kpticbs Feb 02 '24 edited Feb 03 '24
Last line reads like a rastafarian song:
Length I for I in I must range to return Babylon88
u/PityUpvote Feb 02 '24
I think this is the default implementation in Haskell
34
u/SexyMonad Feb 02 '24
I almost like it. And we get to add a performance improvement story later.
33
u/Gravbar Feb 02 '24
TIL py finally added switch statements
2
u/randomlygeneratename Feb 03 '24
I thought I knew python
2
u/sendnukes23 Feb 04 '24
Im stupid. The comments seem to be serious about this. What does OP means when he said missing length function? What about len?
1
u/[deleted] Feb 05 '24
THIS IS GOOD CODE. DEBUGGABLE. WORKS. BIG-O-FAST….