haskell - New at haskel having trouble with String -> Double in list -
I'm enjoying this new language, sometimes it's difficult to harass.
My professor wants, he wants me to accept numbers from the user and calculate an average average.
So far, I leave an error for some kind of error except to my original program.
I am a student in a computer, and this is an assignment question that I am trying to do for me.
Module main (listM, main) where importing system. IiO import data List list = = [1, 2, 3] main = average list M = real listM / genericLength list putStrLn (show (listM)) Now I have this error, Insane running ...: S Q1.hs: 12: 18: Input `= '
on parse error It's good to hear that you are having fun learning Haskell!
As far as your job is concerned: you are not doing any harm at all. I will say: You are almost
As Dwileson explained in his excellent answer, due to the reason that the compiler rejects your program that your definition of listM was previously placed in the importable Haskell module, you Always start with the module headers (sometimes before some programs) and import list and then the definitions of your actions: Module main (main) where importing system IO import data List ... Now, you mention that the compiler (or perhaps interpreter) rejects your program due to "type error". But what is happening is actually a "parse error", it will not be difficult to understand the difference between the two:
-
When the compiler executes your program then It first checks whether your program is syntactically correct. If it is not, it will erase you a parse error.
-
Again, it checks whether you constantly use your functions, that is to check that the type is correct. If they are not, then you have to face a type of error. Generally, the first category of errors is dealt with easily: the compiler almost always tells you on the spot that you made a mistake or a typo in your program (your In case: first import statement). The second category of errors is sometimes more difficult to deal with. But by becoming a good Haskell programmer, you have to familiarize yourself with the type system and actually understand what is happening there (unless it does more or less work, ..) though no worries: it Half can be as hard as you think.
This is looking at your code, it kills me that you define
average xs = realToFrac (Sum listM) / normal long list M That is, you define average to function which takes a logic xs , but that you Do not use xs on the right side of your definition, should xs be considered a list that is calculating the average for you? In your code, your function always calculates the average of the set list listM , whether you list the list as the argument of average besides, your function is fine is. The only thing you need to do now is how to prompt the user for input and how to prepare a list of numbers out of that input.
Good luck ??? And have fun! ;)
Comments
Post a Comment