Why does this Haskell code produce the "infinite type" error? -


I am new to Haskell and I am facing a "Can not create infinite type" error which I I can not understand

In fact, beyond that, I am not getting a good description of this error, so if you can go beyond your original question and explain the "infinite type" error, D Really admires it.

Here's the code:

  intersperse :: a -> [[A]] - & gt; [A] - Interface '*' ["Foo", "Bar", "False", "Quinn"] - Should produce the following: - "Afu * Bar * Falcon * Quixes" - InterSpress-99 [[1, 2,3], [4,5,6], [7, 8 9] - should produce the following: - [1,2,3, -994,5,6, - 99,7,8 , 9] intersperse _ [] = [] intersperse _ [x] = x intersperse s (x: y: xs) = x: s: y: intersperse ss  

and in this interpreter There is an error trying to load it:

  prelude & gt; : Load ./chapter.3.ending.real.world.haskell.exercises.hs [1 of 1] Compiling Heading (chapter.3.exending.real.world.haskell.exercises.hs, Explanation) Chapter 3. Ending .real.world.haskell.exercises.hs: 147: 0: Checks are: Infinite type can not be created: a = [a] when failing to normalize type (s) for `difference ', module Loaded: None   

-

-

Here some code has been corrected and with "infinite type" error in Haskell A general guideline for dealing:

Correct code

intersperse _ [] = [] intersperse _ [x] = x intersperse s (x: xs) = x ++ s: intersperse ss

problem What was:

My signature indicates that the second parameter is intersperse list of lists therefore, when I with "s (x: y: xs)" Matching, X and Y become the list and still I was treating x and y as elements, not the list.

Guidelines for dealing with the "infinite type" error:

Most of the time, when you get this error, Working with variables, types of those types, and you have tried to use a variable such that it is compared to any other type. Carefully see how everything is making versus how you are using it, and it will usually reveal the problem. Text ">

The problem is in the previous section, where you see X and Y as elements, while they are lists. This will work:

  intersperse _ [] = [ ] Intersperse _ [x] = x intersperse s (x: y: xs) = x ++ [s] ++ y ++ intersperse s xs  

Infinite type of error occurs Because: the operator has one -> [A] -> [A], while you treat it [a] -> a -> [a], which means that [a] should be identified with one, its This will mean that this is an unlimited nested list.

Edit : There is another bug in the above code. It should be:

  intersperse _ [] = [] intersperse _ [x] = x intersperse s (x: xs) = X ++ [s] ++ intersperse ss  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -