Friday 15 February 2013

Haskell list comprehension (print sqrt for element of list) -


I have GHCI, version 7.8.3. I want to calculate the sum of the SQLite items, which are divisible by 10.

If I type [x | X & LT; - [10..100], X`Mode`10 == 0] or Yoga [sqrt x | X & LT; - [10..100]] is correct.

But if I write sum [sqrt x] X when an error is displayed:

  '& lt; Interactive & gt; 39: 1: Any examples arising from the use of 'print' (Show T00) type variable 'T' is unclear Note: There are several possible examples in this: Show example twice - 'GHC. Show float defined in float '- define' GHC. Float 'example (integral a, ee show) = & gt; 'GHC. Real 'defined in - GHC release A) ... Show more than 23 other interactive GHCI commands in an STMT: Print it  

How to change the command, which Was the program right?

The problem comes from the fact that when you mod , Then the type of numbers should be integral A = & gt; A , and when you use sqrt , then the type of numbers should be floating a => A . There is no way that the GHC knows about both of these hurdles, however, because you are executing it for any reason due to error message in GHCI is mostly useless error message is similar because GHCi print < / Code>, which calls shows , and for some reason this is the first hurdle that is checked because there is no restriction show , integral , and Floating , this is not a check type.

Type in your other two instances as they only use one of mod or sqrt sqrt : You can get a combination of both to work using to before applying yog [integral x from sqrt $]

 . X & LT; - [10..100], X `mode` 10 == 0]  

No comments:

Post a Comment