Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
*laughs evilly...*
This comment is hidden because it contains spoiler information about the solution
got this error:
yep, it works, thanks :-)
Haskell: get this error when submitting:
That's just something I wanted to write because I found this funny since I'm a pretty stupid person :-)
This comes from the Functor instance on functions defined as
implying that
fmap fmap fmap == (.) . (.)
in this context.This comment is hidden because it contains spoiler information about the solution
At that time, Codewars used to have only python 2, and with python 2,
276 / 30 = 9
.Well, other languages use a NULL value when there is no solution, which translates to Nothing in haskell.
Also (and this is a very personnal opinion), this kata being clearly oriented to beginners, it would be great to show them good practice and make them become accustomed to the Maybe type :-)
Wouldn't this be more "haskellish" to have
sumAndMultiply :: Int -> Int -> Maybe (Int, Int)
?Nope, because in a functor instance,
f :: a -> b
. If you simply domap f toks
, you will try to applyf
onToken a
, this will not type check. You needfmap f
to make this work.Sure, that would be
However, I am not sure you can make an applicative out of this. I think any instance would violate the homomorphism law.
Since you have neither a Functor nor an Applicative instance for your Token type (which is impossible, since
Token :: *
and should be* -> *
), you have no choice but to create a function likeThen with this function, you can do something like
With currying, you could even create a function
And thank you for this challenge, I enjoyed solving it :-)
Nope, it does not :) Just try the lambda function with an example like "1a2b3c".
Loading more items...