1 kyu
Sloth
50lolisa
Loading description...
Functional Programming
Fundamentals
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 have some trouble with this Kata. First of all, it's not clear at all what the
tie
function should do (or, really, any other function). It's relatively straightforward to "guess" what other functions should do from their signature, buttie
's signature is not enough for me. I guess it should be something like "create a dummy thunk in a reference, pass it to the function given and store the result where the dummy thunk was, then return it" but I'm not sure. And, because I'm unsure about that, I'm a little bit confused about what I should do for the fibonacci one.Secondly, I don't understand how it is possible in OCaml to actually make
tail
"lazy enough" with the provided signature. That is, the tests require the head not to be evaluated if I only want to tail of the stream, but since both the head and the tail are in the same thunk, it's impossible to evaluate one without the other. I tried changing the signature of Stream to provide two thunks, but then it doesn't work because the constructor is used directly in the tests (which is strange since the module also provides an interface to create streams).Finally, I'm not sure about which order to use in the join function. Since there are several ways to do that, and that each provides a different stream in the end, it's not clear which one should be chosen.
After some more attempts, I have circumvented the
tail
issue, by realizing it was myjoin
which was not lazy enough! And that's because, even though it was successfully type-checked, it didn't do what it was supposed to because there wasn't a clear explanation about that :| This kata could really benefit from being more precise.I’ll try to answer some of your points without revealing too much of the solution. (Just in case I’ll split the answer so a spoiler flag will not hide everything).
tie
specificaly, it’s hard to wrap your head around how it works - at least that’s my experience. So sorry I can’t help.tail
andjoin
, can (and should) be really lazy. After all it’s a’a L.t
(or aStream
of it), so no evaluation is needed right now.join
, you just need to have every element of the « 2D stream » in the output « 1D stream ». Trying to exhaust the first stream, then the second, etc … will not work because they are, well, infinite.Unfortunately, I know almost nothing about Haskell (if I'm currently 4 kyu in Haskell it's merely because I found Kata were you don't need to know how to code in Haskell to finish them).
My problem about that is how do I reuse already built information. I mean, I don't even know where to put the initializatoin!
After some thoughs, I realized what I was supposed to do for these.
Except it does :') I tested my solution and it [stack overlowed / exceeded the allowed runtime] because the order I chose made it so that you have to wait very long before you actually reach the first element of the n-th stream. But I guess that's easy to fix (just a bit sad that my unpractical solution is rejected). I realized after posting that it was not because a given order was enforced, but rather because mine was really bad.
Thanks for the tips! I think the only thing I am still struggling with is the fibonacci one...
About Haskell, I'm a noob too. I was hinting at the documentation eg. zipWith.
That's the neat part : nowhere. (Well kinda, but no spoil).
Finally about
join
: the order doesn't matter because it is not tested, but the tests still need to access some elements so they have to be at a reasonable position (something exponential would not be reasonable).Ps : does your version of
join
really go through all elements ? If that's not the case then the tests may take elements forever.Well, I have a working thing but I'm not sure it's what was expected. I'll look at the other solutions when I'm done with this kata.
Currently, I am battling a bit with Haskell so my join function doesn't do much; but when it "worked", it indeed went through all elements, except that you would see 2^n elements of the first stream before seeing the first of the n-th stream, which is probably why it broke down (NB. when I click on Attempt, it successfully passes the first batch of tests for
LazyThunk
, but not forLazyOption
, because it times out — so the implementation is correct, it's just too long)... Whatever, I guess I'll just change the order, even if that's a bit longer to code.This comment has been hidden.
Oh I figured it out. It must happen in such an order that those coordinates can be reached within finite time.
I'm leaving this comment here as a hint because the requirement is frustratingly uninformative.
This comment has been hidden.
It is the famous Landin's knot.
The description is actually terrifying... Well, since I've seen your other kata, I've got a fair idea of how this one is going to go. 🦥
One day, I'm going to click "Train" on this kata—one day!
You can copy the url and paste it (add
/train
at the end) in a tab where you're logged off ...This comment has been hidden.
I'm now so impressed by GHC optimizations...
This comment has been hidden.
This comment has been hidden.
Done
Approved!
Praise the Marisa! > <
This is so tough for me, and very enlightening. I think it's worth a 1kyu, at least no less than any other 1kyu kata lol.
It is even tougher now, as I require a O(n) join function.
If I understand the
join
ofstream
correctly, it takes the diagnol infinite matrix generated by the stream of streams, like the one here:so how could I encounter
(2, 3)
in the product of twoS.gen (fun n -> 1 + n) (L.return 0)
s?You need to traverse every single element.