在Haskell中修改“break”?
在Haskell中修改“break”?,haskell,Haskell,break具有签名[a]->(a->Bool)->([a],[a])其中第一个元组等于,据我所知,takeWhile谓词为true。第二个元组是负责使谓词为false加上剩余列表的项 > break (== ' ') "hey there bro" ("hey"," there bro") 但是,是否有一个函数将跳过负责破坏的项 >foo? (== ' ') "hey there bro" ("hey","there bro") 不在标准库中,但您可以方便地使用配对的Functo
break
具有签名[a]->(a->Bool)->([a],[a])
其中第一个元组等于,据我所知,takeWhile谓词为true
。第二个元组是负责使谓词为false加上剩余列表的项
> break (== ' ') "hey there bro"
("hey"," there bro")
但是,是否有一个函数将跳过负责破坏的项
>foo? (== ' ') "hey there bro"
("hey","there bro")
不在标准库中,但您可以方便地使用配对的
Functor
实例将1拖放到元组的第二个元素上:
break (== ' ') "hey there bro"
== ("hey"," there bro")
drop 1 <$> break (== ' ') "hey there bro"
== ("hey","there bro")
但是,在使用元组时,我通常更喜欢使用Control.Arrow中的second
,而不是fmap
,因为它更好地表达了意图:
second (drop 1) $ break (== ' ') "hey there bro"
== ("hey","there bro")
break'=(fmap尾部)。中断
。这是部分的,所以您需要类似于break'=(fmap tail')的内容。如果tail'x=为空x,则[]否则tail x
@user 2407038您的tail'
与drop 1
相同。该lambda字符是标识符、提示字符串还是?提示。谁没有:在他们的.ghci文件中设置提示符“λ”
?@JonPurdy被困在windows上,找不到他们喜欢的、支持unicode的终端仿真器=(@bheklillr Argh为什么你要这么说,当然我必须试试!各位,不要在WinGHCi中尝试,我必须使用regedit删除提示设置,这样我才能让它重新启动D:@rjanJohansen如果你使用Cygwin,你可以在某种程度上让它在模拟程序中工作,比如Console2和ConEmu。默认的cmd.exe
shell已经没有正确的unicode支持,所以你在这里完全是运气不佳。我以前让库破坏了一个cmd.exe
shell,因为我尝试了:browse Module.Name
,它使用了unicode标识符。TL;DR:Windows上没有unicode。
second (drop 1) $ break (== ' ') "hey there bro"
== ("hey","there bro")