kowainik / slist

♾️ Sized list
https://kowainik.github.io/projects/slist
Mozilla Public License 2.0
46 stars 6 forks source link

[#6] Add generic functions #18

Closed waynee95 closed 5 years ago

waynee95 commented 5 years ago

Resolves #6

genericTake differs syntactically from take for Slist. Personally, I liked this more. If it should be consistent, I can change it to fit the style of take.

waynee95 commented 5 years ago

Sure, I will add the tests! I was wondering why there were no tests in the test directory, but doctests explain it! Never seen that before, but it's cool.

I have a question. What does the __ mean here? And why is there only two >>?

>> __splitAt 2 $ 'infiniteSlist' [1..]__

Maybe I missed something on the docu site of doctest.

vrom911 commented 5 years ago

Oh, yeah, I also find doctests crucial in keeping docs up to date!

This particular example is not the doctest, you can notice that it surrounded by @s and considered only as a code block. The reason is that we can not really test it with the infinite lists (we won't be able to show it in the terminal). And __ here is just Haddock syntax for bold text, so it for visual effects only :slightly_smiling_face:

waynee95 commented 5 years ago

Oh right! Okay, gonna add the tests and genericAt.

waynee95 commented 5 years ago

@vrom911 I added tests for the generic functions. So far the tests are similar to the non-generic ones. Should I also add test cases for passing arguments either as Int or Integer explicitly? :thinking:

vrom911 commented 5 years ago

Should I also add test cases for passing arguments either as Int or Integer explicitly? thinking

No, due to monomorphism restriction current tests are already for Integer so no need to add more tests. It's now cool, great job :1st_place_medal:

waynee95 commented 5 years ago

In general, wouldn't there be an issue when i is of type Integer and we cast it to Int, because Integer can be much bigger?

vrom911 commented 5 years ago

Yes, I agree that fromInteger is not always a safe thing to do, as you mentioned. But here we are limited by the fact that Size stores Int by design and this was done assuming that usually people don't work with such huge lists, it's either in the range of Int or infinite. So, it's okay to do it this way :slightly_smiling_face:

waynee95 commented 5 years ago

@vrom911 First time using languages extensions/view patterns. It's kinda neat though. Did I do it correctly? :sweat_smile:

waynee95 commented 5 years ago

I misclicked on my phone :laughing: