News for hackers. Stuff that matters.
Re:Exploring the C# 6 Null Propagation Operator by Arguggi on Sunday April 19, 2015 @01:53PM (#9404035)
This seems pretty similar to the Haskell Maybe Monad.

"Learn You a Haskell for Great Good!" has an example[0]:

  routine =   
    case Just (0,0) of   
        Nothing -> Nothing  
        Just start -> case landLeft 2 start of  
            Nothing -> Nothing  
            Just first -> case landRight 2 first of  
                Nothing -> Nothing  
                Just second -> landLeft 1 second
becomes (using some 'do' syntactic sugar):

  routine = do  
    start <- return (0,0)  
    first <- landLeft 2  
    second <- landRight 2 first  
    landLeft 1 second
Checking for Nothing is taken care of 'automatically' and if any of start, first, second or (landLeft 1 second) are equal to Nothing routine is equal to Nothing too.

[0] http://learnyouahaskell.com/a-fistful-of-monads#walk-the-lin...

Re:Exploring the C# 6 Null Propagation Operator by kristianp on Sunday April 19, 2015 @06:44PM (#9405189)
This isn't really the same thing. Haskell (and Ocaml) make you deal with the null case, whereas C# just lets you propagate the nulls. Haskell's way is safer, c# is just handy syntax.
Re:Exploring the C# 6 Null Propagation Operator by bbcbasic on Sunday April 19, 2015 @05:14PM (#9404906)
Which goes to show that what requires a 'new feature' in C# is just a freebie in Haskell, due to the powerful type system. See my other comment ITT for how to do this in a tighter way that is more like the C# syntax. (You just use the bind operator rather than wrapping it in a do)
Re:Exploring the C# 6 Null Propagation Operator by acjohnson55 on Sunday April 19, 2015 @02:44PM (#9404258)
It's basically the same thing, except with that syntax, you have to label all the intermediate results
Re:Exploring the C# 6 Null Propagation Operator by bbcbasic on Sunday April 19, 2015 @05:06PM (#9404874)
To avoid labeling:

    routine :: Int -> Maybe Int  
    routine n = Just n >>= (divisorFilter 3) >>= (divisorFilter 2) >>= (divisorFilter 5)

    -- Supporting function
    divisorFilter :: Int -> Int -> Maybe Int
    divisorFilter d n
        | n `mod` d == 0 = Just n
        | otherwise = Nothing
        
    -- Using do syntax
    routine' :: Int -> Maybe Int  
    routine' n = do  
        first <- divisorFilter 3 n
        second <- divisorFilter 2 first
        divisorFilter 5 second