Learning Haskell: How to remove an item from a List in Haskell

前端 未结 7 1149
伪装坚强ぢ
伪装坚强ぢ 2021-02-01 19:06

Trying to learn Haskell. I am trying to write a simple function to remove a number from a list without using built-in function (delete...I think). For the sake of simplicity, le

7条回答
  •  清歌不尽
    2021-02-01 19:42

    I believe all the solutions given so far work differently than Data.List.delete, which only deletes the first member.

    deleteFromList x xs =
      case break (==x) xs of
        (_,[]) -> xs
        (notsat,sat) -> notsat ++ tail sat
    

    was my attempt to delete only the first member (haven't peaked at D.L yet).

    It's unclear which behavior the top poster wants.

提交回复
热议问题