简体   繁体   English

有人可以解释这个Haskell吗?

[英]Can someone explain this Haskell?

Been working on some homework with some great help from some members, but a course fellow just showed me this. 一些成员在一些家庭作业上做了很多帮助,但是一位课程老师只是向我展示了这一点。 It boggles my brain the format and exactly how its working? 它让我的大脑难以理解它的工作原理和格式。 I tried to tweak it to learn about it but I don't get it. 我试图调整它以了解它,但我没有得到它。

fun2 :: String -> [String]
fun2 [] = []
fun2 (x:xs) = [fun1 (x:xs)] ++ runs (drop (length (munch (x:xs))) (x:xs))

fun1 is : fun1是:

fun1 (x:xs) = group (x:xs)

Could someone break this down for me in the aids of learning? 有人可以在学习辅助工具中为我打破这个吗? Using one function into another is required by the work. 工作需要将一个功能用于另一个功能。

Again this is homework, I'm just asking for guidance to understand Haskell as I can't get my head around it! 再次这是家庭作业,我只是要求指导理解Haskell,因为我无法理解它!

Some pseudocode to explain what's happening when fun2 is called: 一些伪代码解释当调用fun2时发生的事情:

if the argument is [] (the empty list)
    return []
else (the argument is a non-empty list x:xs)
    fun1Result = fun1 (x:xs)
    fun1List = [fun1result]   -- a list of one element
    munchResult = munch (x:xs)
    lengthResult = length munchResult
    dropResult = drop lengthResult (x:xs)
    runsResult = runs dropResult
    return fun1List ++ runsResult  -- concatenate the two lists

In Haskell, functions are applied just by putting a space between the function and the argument. 在Haskell中,只需在函数和参数之间放置一个空格即可应用函数。 So fx calls function f with the value x . 所以fx用值x调用函数f Function application is evaluated from left to right, so the parenthesis are just there to make sure everything happens in the right order. 函数应用程序从左到右进行评估,因此括号就是确保一切按正确的顺序进行。

Hopefully this makes the syntax less confusing. 希望这会使语法不那么混乱。 I don't think munch or runs are standard functions, so I can only guess at what they do. 我不认为munchruns是标准函数,所以我只能猜测它们的作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM