Skip to content

Instantly share code, notes, and snippets.

@recursivecurry
Last active August 29, 2015 14:21
Show Gist options
  • Save recursivecurry/86100c8c2fd6aa1f189d to your computer and use it in GitHub Desktop.
Save recursivecurry/86100c8c2fd6aa1f189d to your computer and use it in GitHub Desktop.
[1 of 1] Compiling Main ( test.hs, test.o )
test.hs:8:36:
No instance for (Num (a0 -> Double)) arising from a use of `y'
Possible fix: add an instance declaration for (Num (a0 -> Double))
In the first argument of `(*)', namely `(y x)'
In the expression: (y x) * 0.001
In the first argument of `sum', namely
`[(y x) * 0.001 |
x <- [(fromIntegral l) + 0.0005, (fromIntegral l)
+ 0.0015 .. (fromIntegral r)]]'
test.hs:8:55:
No instance for (Enum a0)
arising from the arithmetic sequence `(fromIntegral l)
+ 0.0005, (fromIntegral l) + 0.0015 .. (fromIntegral r)'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Enum Double -- Defined in `GHC.Float'
instance Enum Float -- Defined in `GHC.Float'
instance Integral a => Enum (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
...plus 7 others
In the expression:
[(fromIntegral l) + 0.0005, (fromIntegral l)
+ 0.0015 .. (fromIntegral r)]
In a stmt of a list comprehension:
x <- [(fromIntegral l) + 0.0005, (fromIntegral l)
+ 0.0015 .. (fromIntegral r)]
In the first argument of `sum', namely
`[(y x) * 0.001 |
x <- [(fromIntegral l) + 0.0005, (fromIntegral l)
+ 0.0015 .. (fromIntegral r)]]'
test.hs:8:72:
No instance for (Num a0) arising from a use of `+'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Num Double -- Defined in `GHC.Float'
instance Num Float -- Defined in `GHC.Float'
instance Integral a => Num (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
...plus three others
In the expression: (fromIntegral l) + 0.0005
In the expression:
[(fromIntegral l) + 0.0005, (fromIntegral l)
+ 0.0015 .. (fromIntegral r)]
In a stmt of a list comprehension:
x <- [(fromIntegral l) + 0.0005, (fromIntegral l)
+ 0.0015 .. (fromIntegral r)]
test.hs:8:73:
No instance for (Fractional a0) arising from the literal `0.0005'
The type variable `a0' is ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there are several potential instances:
instance Fractional Double -- Defined in `GHC.Float'
instance Fractional Float -- Defined in `GHC.Float'
instance Integral a => Fractional (GHC.Real.Ratio a)
-- Defined in `GHC.Real'
In the second argument of `(+)', namely `0.0005'
In the expression: (fromIntegral l) + 0.0005
In the expression:
[(fromIntegral l) + 0.0005, (fromIntegral l)
+ 0.0015 .. (fromIntegral r)]
import Text.Printf (printf)
-- This function should return a list [area, volume].
solve :: Int -> Int -> [Int] -> [Int] -> [Double]
solve l r as bs = [area]
where
y x = sum $ zipWith (\a b -> (fromIntegral a)(x*(fromIntegral b))) as bs
area = sum [(y x) * 0.001 | x <-[(fromIntegral l)+0.0005, (fromIntegral l)+0.0015..(fromIntegral r)]]
--Input/Output.
main :: IO ()
main = undefined
--main = getContents >>= mapM_ (printf "%.1f\n"). (\[a, b, [l, r]] -> solve l r a b). map (map read. words). lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment