These are chat archives for ramda/ramda

21st
Jan 2017
Stefano Vozza
@svozza
Jan 21 2017 12:48 UTC
is there a way to write this with guards without needing the Eq constraint?
splitAt' :: Eq a => Int -> [a] -> ([a], [a])
splitAt' num xs = go num ([], xs)
where go n (ys, zs)
| zs == []  = (ys, zs)
| n == 0    = (reverse ys, zs)
| otherwise = go (n - 1) ((head zs):ys, tail zs)
Denis Stoyanov
@xgrommx
Jan 21 2017 12:53 UTC
@svozza ramda has split
Stefano Vozza
@svozza
Jan 21 2017 13:07 UTC
Yeah, I know. I'm just playing around with recursion in haskell
Syaiful Bahri
@syaiful6
Jan 21 2017 13:21 UTC
you can, but not as pattern guard.
if you match like that then you need Eq for a. but if you write like this, you dont need it.
@svozza
splitAt' :: Int -> [a] -> ([a], [a])
splitAt' num xs = go num ([], xs)
where
go n (ys, []) = (ys, [])
go 0 (ys, xs) = (reverse ys, xs)
go n (ys, xs) = go (n - 1) (head(xs):ys, tail xs)
this declaration make you need Eq constrain zs == []
Syaiful Bahri
@syaiful6
Jan 21 2017 13:39 UTC
Alternatively you can match the length of zs with 0.
Stefano Vozza
@svozza
Jan 21 2017 13:43 UTC
Ah yes, that looks great. I knew there was something simple I was missing
mikiubo
@mikiubo
Jan 21 2017 20:58 UTC
I have a question: i have a curried function with 3 args. I want to compose only on the 3 arg it is possible?
Brenton Alker
@tekerson
Jan 21 2017 21:20 UTC
@mikiubo you can partially apply the first 2 arguments to the 3 arg function, then compose the remaining function (which has 1 argument left). Is that what you mean?
mikiubo
@mikiubo
Jan 21 2017 21:28 UTC
@tekerson yes and no... because i have a lot of different partially applied functions and all this different functions need the same composition on the third parameter so if i follow your method i need to rewrite this composition all the time