Can someone explain this Haskell?

Worked on some homework with some great help from some members, but the cadet just showed me this. Does it scare my brain with the format and exactly how it works? I tried to configure it to find out about it, but I do not understand.

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

fun1:

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

Can someone break this for me to help? Work from one function to another is required.

Again, this is homework, I just ask to make it clear how Haskell understands how I can not get around him!

+3
source share
1 answer

Some pseudo code to explain what happens when fun2 is called:

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

Haskell . , f x f x. , , , .

, . , munch runs , , .

+3

Source: https://habr.com/ru/post/1795624/


All Articles