4 ms·
I feel like this is why types have such a benefit in Haskell. This would be typed walkValues :: (v -> a) -> Map k v -> Map k a silent :: (inp -> Ei
by tel 12y ago
I feel like this is why types have such a benefit in Haskell. This would be typed
walkValues :: (v -> a) -> Map k v -> Map k a
silent :: (inp -> Either e a) -> (inp -> Maybe a)
Here, `silent` is the contextualized version of a really standard error-ignoring combinator which simply throws away the additional error details conveyed in `Either`.
silent' :: Either e a -> Maybe a
`walkValues` is an extraordinarily common function usually called `fmap` and its existence tells us that `Map` is a `Functor`
instance Functor (Map k) where
fmap = walkValues
Ultimately, this pattern is really common and would be written in Haskell as
fmap (silent' . int)
The types ensure it cannot be used incorrect. The notion of `Functor` happy compresses all ideas of "mapping" such as what walk_values is doing.
- tinco 12y agoI love Haskell, and I totally agree with you, but I don't think you're making much of a case to people who don't already know Haskell. I'm pretty sure everyone who doesn't grok Haskell reads your post and thinks "Ah there's another Haskell weirdo spouting some weird syntax incomprehensible code." So for them: What tel is saying is that in Haskell you annotate your functions with type information (and if you don't the compiler will generate the info for you), which gives you an immediate understanding of what moves into and out of a function, often making it easier to understand what a high level function does.