haskell parse error in pattern for n+k pattern

后端 未结 2 612
后悔当初
后悔当初 2021-02-07 07:11

I have started working my way through Erik Meijer\'s 13-part lectures (and Graham Hutton\'s slides) to learn Haskell.

On the slides for Chapter 4, on page 13, it intro

2条回答
  •  逝去的感伤
    2021-02-07 07:29

    You have to enable it by -XNPlusKPatterns.

    ghci -XNPlusKPatterns
    Prelude> let mypred (n+1) = n
    Prelude> mypred 2
    1
    

    Similarly in a hs file.

    {-# LANGUAGE NPlusKPatterns #-}
    
    mypred :: Int -> Int
    mypred (n+1) = n
    

    After loading in ghci

    *Main> mypred 2
    1
    

提交回复
热议问题