Learning Haskell maps, folds, loops and recursion -


As part of my journey of programming knowledge only, I've only dropped my toe in the world of Haslekel (Moving from,

I'm trying one online.

However, now I'm stuck on a problem:

A simple Create a function, which gives the total amount of an array of numbers.

In a procedural language it's easy for me (recursion By using) (c #):

  Private Ent Sum (Arrayist X, Int i) {if (! (X.Count & lt; i + 1)) {int t = 0 ; T = x.Item (i); t = yoga (x, i + 1) + t; return t;}}  

all are very fine, though my failed attempt at Haskel The following error occurred as follows:

  sum sum x = x + sum sum map [1..10]  

From:)

  can check: can not create infinite types: a = a -> please  

Please note that I've only used Haskel for the last 30 minutes!

I'm not just looking for an answer, but more clarity about it.

I'm not looking for only one answer, but more explanation about it.

To the left hand side as the function you applied to sum on x . The compiler is not aware of the type of x , so the compiler uses type variable " a to stand for" type of code " is. Thus at this point that the compiler does not know the result type of the sum function, so that it can create another type of variable, thus creating t for the result type. Chooses for Now the compiler on the left hand thinks that x is of a -> Accepting T ( a and accepting the returning code function.)

= On the right side of Add x and yoga . All types of numbers can be added to Haskell, but you can add two numbers only if they have type same , then the compiler here believes that in sum One type is x , i.e. a .

But Haskell has a type of identifier & mdash; There may be a complex type, but still a type contains sum , which should be 'identical' on both sides of the sign, so the compiler tries to solve the equation.

  a = a - & gt;  

There is no value for this equation resolver a and t . This is not the only thing that is equal to a that is equivalent to the a function which accepts itself as logic, thus error The message is generated

  can not create infinite types: a = a -> 

Even with all the explanations, this is not a big error message, is it?

Welcome to Haskell: -)


PS You can enjoy learning "helium, learning Haskell", which is a very good error for beginners Message.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -