News for hackers. Stuff that matters.
Re:Kotlin: The Problem with null by yiransheng on Friday January 12, 2018 @08:01PM (#16137628)
In languages like Haskell and Scala that supports `do` / `for` comprehension sugar, this could be done without the nesting:

  fn :: Maybe Int -> Maybe Int -> Int
  fn q z = fromMaybe 0 $
    do 
      q_in <- q
      z_in <- z
      return (q_in + z_in)
Re:Kotlin: The Problem with null by willtim on Saturday January 13, 2018 @03:49AM (#16138797)
In modern Haskell, we are more likely to use the Applicative instance for Maybe, e.g.

    fromMaybe 0 $ 
        (+) <$> xm <*> ym
Re:Kotlin: The Problem with null by zenhack on Friday January 12, 2018 @09:27PM (#16137926)
Or just:

    fn (Just q) (Just z) = q + z
    fn _ _ = 0
Re:Kotlin: The Problem with null by masklinn on Saturday January 13, 2018 @06:35AM (#16139191)
Surely since you have monads you can just use the tools they give you?

    fn = liftM2 (+)
Re:Kotlin: The Problem with null by zenhack on Saturday January 13, 2018 @01:33PM (#16140587)
That doesn't do quite the same thing; the original example gets rid of the Maybe, defaulting to 0.
Re:Kotlin: The Problem with null by masklinn on Monday January 15, 2018 @04:30AM (#16149503)
> That doesn't do quite the same thing

You're missing the point entirely.

> the original example gets rid of the Maybe, defaulting to 0.

http://hackage.haskell.org/package/base-4.10.1.0/docs/Data-M...

Re:Kotlin: The Problem with null by brabel on Saturday January 13, 2018 @04:39AM (#16138923)
Wouldn't this let me call `fn true false` or `fn "hi" 2`? Or the second declaration takes the inferred type of the arguments from the first one?
Re:Kotlin: The Problem with null by andolanra on Saturday January 13, 2018 @05:43AM (#16139053)
This isn't two functions: it's actually one function defined by cases. You can think of it as equivalent to

    fn x y = case (x, y) of
      (Just q, Just z) -> q + z
      (_, _) -> 0
but the case becomes implicit in the repetition of the function name at the top level of indentation.
Re:Kotlin: The Problem with null by dllthomas on Saturday January 13, 2018 @12:11PM (#16140260)
> at the top level of indentation

At the same level, really - it works in a let or a where as well.