Why does this Haskell code produce the “infinite type” error?

后端 未结 4 1542
青春惊慌失措
青春惊慌失措 2020-12-13 03:27

I am new to Haskell and facing a \"cannot construct infinite type\" error that I cannot make sense of.

In fact, beyond that, I have not been able to find a good exp

4条回答
  •  春和景丽
    2020-12-13 04:08

    I may be wrong, but it seems you're trying to solve a more difficult problem. Your version of intersperse doesn't just intersperse the value with the array, but also flattens it one level.

    The List module in Haskell actually provides an intersperse function. It puts in the value given between every element in the list. For example:

    intersperse 11 [1, 3, 5, 7, 9] = [1, 11, 3, 11, 5, 11, 7, 11, 9]
    intersperse "*" ["foo","bar","baz","quux"] = ["foo", "*", "bar", "*", "baz", "*", "quux"]
    

    I'm assuming this is what you want to do because it's what my professor wanted us to do when I was learning Haskell. I could, of course, be totally out.

提交回复
热议问题