1

This is in the context of writing a function description. Let's say I have the function:

fromMaybe :: a -> Maybe a -> a
fromMaybe _ (Just x) = x
fromMaybe d Nothing = d

Would it be correct to say that this function "converts an object of type 'Maybe a' into type 'a' by using a fallback argument"?

Of course, in Haskell, nothing is actually really converted, something else entirely is being returned. That is the background of this question. Is the usage of the term 'convert' OK to use? If so, when is it not?

What if I have a function that takes a list of Integers and returns a list that is exactly the same, but with Floats. Would it be proper to say: "this function converts a list of Integers into a list of Floats"?

bjm
  • 98
  • 6
  • 1
    I personally would use the term "converts" for things like `fromIntegral` which you seem to be talking about in the last paragraph. I wouldn't naturally think of `fromMaybe` that way - but I don't think it's an unreasonable viewpoint either. Ultimately I think it's a matter of opinion. – Robin Zigmond Feb 07 '19 at 00:01
  • 3
    Convert implies some sort of light casting to me - your ints to floats is one example where I might say "convert". However, `fromMaybe` is vastly different just like looking up the value in a map and returning it or a default if nothing was found. In this case I'd say you are computing a result or simply "computes on values of type `Maybe a`, returning values of type `a`". Notice the term "values" instead of "objects". – Thomas M. DuBuisson Feb 07 '19 at 00:13
  • I think the term `convert` is fine but personally I would prefer term [map](https://en.wikipedia.org/wiki/Map_(mathematics)) which unfortunately might cause confusion with the higher order function [one](https://hackage.haskell.org/package/base/docs/Prelude.html#v:map). – wizzup Feb 07 '19 at 07:24
  • 1
    also "transform". – Will Ness Feb 07 '19 at 09:16

0 Answers0