1 kyu
Lensmaker
389tel
Loading description...
Fundamentals
Functional Programming
Puzzles
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
I'm having the same trouble as the user below me. My solution is correct and I'm not using any Lens imports but I'm getting the following error: uncaught exception: IOException of type UserError user error (Could not parse solution correctly)
Try to add
{-# LANGUAGE Haskell2010 #-}
and fix compilation errors. It seems the issue is because of lib used to validate imports. It fails if code is not a valid Haskell2010.Still did not fix
I tried to run your solution without
{-# LANGUAGE ImportQualifiedPost #-}
and tests passed. You also need to changeimport Data.Traversable qualified as T
toimport qualified Data.Traversable as T
Wow, thanks! I wonder what's causing this...
This comment has been hidden.
How to avoid the following error on the test case
Cannot use Control.Lens
? I did not import anything that relates toControl.Lens
.I see.
RankNTypes
should be made available forTupleSections
to work. The above error will occur when{-# LANGUAGE RankNTypes #-}
is missing. Sorry for the stupid question.I'm also getting this error but i DO have RankNTypes enabled..
Very scary, but surprisingly pretty easy, just follow the types (some of them are singletons !)
Really nice kata, thanks tel !
It is satisfctory, but I wish it could give more thorough explanation and type replacements. Especially, how each part of it works. (And what actually is a profunctor)
what's mean a type? use not a
newtype K b a = K { getK :: b } deriving Functor
Very nice. Managed to follow almost all of it, but still don't quite get prisms. Follow the types!
This was fantastically satisfying! Took me several days of leaving and coming back to it, and some reading about lenses/profunctors/contravariant functors. I learned a lot from this.
probably the hardest kata I ever solved :) I still don't get most of it. ghc typed holes can help a lot.
Thanks for putting this together. Working this kata did a lot to force me to understand how lenses work.
awesome kata, and to understand why those type signature work is more difficult than implement those function
I like this kata, so many lenses, perfect
I've completed this kata, but I still have no idea about wtf is
Lens
...I think I should read more books about Haskell. This kata is awesome. Thank you @tel.
Description is improved, and test case is now completed. It's time to approve this new 1kyu Haskell Kata.
Wow! The first Haskell-specific 1kyu kata approved! Cheers!
It seems that it's possible to pass this cata without implementing 'coerce' and 'over', is porttible to add tests for those?
Typo: it's
kata
, notcata
.And I've added tests for them. Issue closed.
I don't quite understand 'coerce' and didn't try hard to implement it. Is it feasible to add at least primitive tests for it?
Thanks!
to
is intended to be implemented based oncoerce
, so the original author didn't test for it as a standalone function.There is test for that function now.
This is madness. I actually used the most time to figure out what the types are and how to put them together. I wish I learned a bit more, but not sure whether it is worth, seems pretty complicated.
There's a lot to analyze, to be completely fair. i would suggest reading some material on more basic formulations of lenses to see better how this one comes to be.
But that said, type-tetris level understanding is where I personally began understanding this material as well, so it's a meaningful first step.
Lenses are great. I recommend the video by Edward Kmett (author of
lens
), or this introduction.This comment has been hidden.
This comment has been hidden.
Thanks!
This looks like a really cool kata, but the lenses are explained really poorly - I can't make head or tail of a couple. Could you maybe add some online refrences or explain a bit further?
Which ones? I'm kind of trying to keep it oblique to not (a) have to go through an entire lens tutorial and (b) keep people thinking around the types instead of the semantics. I'd really love detailed feedback to help drive it to a good compromise here.
Last Iso thing is still untested (at least, in provided tests)
Good catch—added!
Bleh. I didn't know lenses before I started, and I still dont know how most of the lensy things I just wrote work. This was frustrating; basically just blindly following types, with no intuition. What is a Protofunctor? What is a "witness"? Some crazy category theory stuff I guess?
Towards the end of it, I was just motivated by sunk cost (and wanting to complain about how annoying it was).
The last Iso problem is untested (so I could have left it blank), and I have no idea what "coerce" was about but it seemed to be happy with it as bottom, so I didn't touch it.
Side note: Either is not traversable in this version of haskell, so I implemented it myself.
While I agree that writing the individual lenses feel a bit abstract, I thought that writing
over
andset
gives an excellent hint on how the machinery works.A profunctor (not a protofunctor) is something looks like a bifunctor (like (,) or Either), except the first argument is contravariant (if that means something). My intuition for it is that
Profunctor p => p a b
represents somethings that "consumes" ana
and "produces" ab
, for examplea -> b
. Withlmap
you can "adapt the source" andrmap
changes the output, likefmap
.I think a "witness" is just another word for a piece of code that serves as a proof.
But all the lens stuff is crazy category theory stuff, so I suppose you need to learn some of it if you want to grok it.
Whilst useful, I think the
_Left
and_Right
exercises are a bit too hard, especially since the types are pretty hard to read, and it's non-obvious what thosePrism
s are al about.Did you consider monomorphing the
p
to->
(assuming that's possible)? This might make types easier to grok. If not, maybe adding another example of ap
instance could be useful.This comment has been hidden.
This comment has been hidden.
Well, I'd say the real challenge is figuring out what it means once you have written something that type checks. I'm not there yet !
The test cases don't cover
_Right
.I added a test case, thanks!
People who haven't encountered Van Larhoven lenses will be unable to succeed.
The goal is precisely to drive people to learn more about van Laarhoven lenses :)
I disagree, this is doable by pure type-tetris, with no previous knowledge of the theory.
My hope was that would be the case. The "lens use functions" reveal a lot of type information. I could have written them to take types quantified over the functor and profunctor, but that is both non-standard and harder to type-tetris.
A beauty of this Kata is that it's a great first encounter with Van Larhoven lenses itself.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Not sure if the changes are supposed to be atomic, but the "commit" button does require
to
, and it's not in the default solution or test cases as far as I can see.Ah, thank you! That is a bug. I forgot to track the public test cases to the behind-the-scenes ones.
It should be fixed now, please let me know if you find any remnants. Thanks!
There is now
to
in the solution skeleton, but I can't reset the provided tests, so I can't check if it's in there too :(The test involving
sum
was replaced withLooks fine to me !
You'll want to hide
Control.Lens
...Oh, that's built in? Is there a listing of available modules?
Not exactly, I should make one.
All of the code runs in a docker container. I started installing various modules when I needed them:
https://github.com/Codewars/codewars-runner/blob/master/docker/func.docker
It may be a good idea to just use Stackage perhaps?
This comment has been hidden.
There are many more lens concepts which could be included into this Kata to increase its challenge!
Yes, all the indexed stuff makes me scratch my head. Perhaps having to implement it would help ...
This comment has been hidden.