写了一个Python风格的字符串split函数……

14 views
Skip to first unread message

Blade Wang

unread,
May 30, 2010, 3:58:36 PM5/30/10
to haskell.cn

RT,不知有没有更好的方式来作和Python中string.split相同的事?

这是我写的一个,请路过的各位大虾指点!


> module MySplit (split) where

> split :: String -> String -> [String]

> split s tkn | l == 0 = [s]
> | otherwise = _split s
> where
> l = length tkn


> _split x | tkn == take l x =
> "": (_split $ drop l x)

> | null x =
> "":[]

> | otherwise =
> (head x : head sp) : tail sp
> where
> sp = _split $ tail x


Reply all
Reply to author
Forward
0 new messages