What does the “Just” syntax mean in Haskell?

后端 未结 5 1616
说谎
说谎 2020-12-07 08:33

I have scoured the internet for an actual explanation of what this keyword does. Every Haskell tutorial that I have looked at just starts using it randomly and never explain

5条回答
  •  旧时难觅i
    2020-12-07 09:02

    Function if (cond :: Bool) then (ifTrue :: a) else (ifFalse :: a) must have the same type of ifTrue and ifFalse.

    So, when we write then Nothing, we must use Maybe a type in else f

    if balance < reserve
           then (Nothing :: Maybe nb)         -- same type
           else (Just newBalance :: Maybe nb) -- same type
    

提交回复
热议问题