Eq => function in Haskell

后端 未结 2 1886
迷失自我
迷失自我 2021-01-28 13:25

I am trying to figure out how to write this function with the Eq function in Haskell.

An easy function that I am trying to implement is:

f :: Eq a =>          


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-28 13:57

    You can also use span and a recursive call to make it work:

    f :: Eq a => [a] -> [[a]]
    f [] = []
    f l@(x:xs) = grouped : f remainder
        where
            (grouped, remainder) = span (== x) l
    

    Here you have the live example

提交回复
热议问题