###
December 2015 1HaskellADay 1-Liners

**One-liners**
- December 30th, 2015: You have a string of 'digits' in base whatever to convert to an Int

debase :: [Int] -> Int -> Int

debase [12,21,3] 26 ~> 8661

Define debase
- Gautier DI FOLCO @gautier_difolco

import Data.Bifunctor

debase = curry (sum . uncurry (zipWith (*)) . bimap reverse (flip iterate 1 . (*)))
- bazzargh @bazzargh

debase a b = sum $ zipWith (*) (reverse a) (map (b^) [0..])
- obadz @obadzz

or debase l b = foldl (\ p n -> p * b + n) 0 l
- bazzargh @bazzargh

that's better than mine. how about:

flip (foldl1 . ((+) .) . (*))

- December 12th, 2015: #math
You have this sequence: [1,1,1,1,1,1,2,1,1,1,3,3]
What is this pattern? Is there one?
Write #haskell to generate this list.
- December 3rd, 2015: Lens-y again
Points-free-itize the following
correctName :: Row -> Row
correctName r = set lastName (init (view lastName r)) r
- December 3rd, 2015: Let's get a little lens-y with this one:
accumer :: Getter a t a -> t -> [a] -> [a]
accumer f s acc = ans
where ans = view f s:acc
- Define the curried-accumer function that curries away the acc-argument.
- What would the curried definition be if the function type were:
accumer :: Getter a t a -> t -> Set a -> Set a

- December 3rd, 2015:
define minimax :: Ord eh => eh -> (eh, eh) -> (eh, eh)
such that, e.g.:
minimax 1 (2,3) ~> (1,3)
minimax 10 (2,3) ~> (2,10)
- Thomas Dietert @thomasdietert In that case,
minimax n (x,y) = (minimum [n,x,y], maximum [n,x,y])
- joomy @cattheory minimax = liftM2 (***) min max

- December 1st, 2015: define (->>) :: (a -> m ()) -> (a -> m ()) -> a -> m () All monadic effects must be evaluated.
- Jérôme @phollow (->>) f g a = f a >> g a
- then liftM2 (>>)
- Nicoλas @BeRewt but the full applicative is: liftA2 (*>)

## No comments:

Post a Comment