[Haskell-cafe] Facing issue: "No instance for (Fractional a0) arising from a use of ‘it’ The type variable ‘a0’ is ambiguous"

Balraj Singh erbalrajs at gmail.com
Mon Sep 12 18:08:47 UTC 2016


Hi,

I am writing a sample code below and getting an error. Please help to
resolve it:

Code:

import Data.List


findLoot val [] = 0.0

findLoot val ((x:y:[]):xs) | val == 0 = 0.0

                           | val < y  = ((fromIntegral val) * (fromIntegral
x)) / fromIntegral y

                           | val > y  = ((div val y)*x) + (findLoot (mod
val y) xs)


Error:

No instance for (Fractional a0) arising from a use of ‘it’

    The type variable ‘a0’ is ambiguous

    Note: there are several potential instances:

      instance HasResolution a => Fractional (Fixed a)

        -- Defined in ‘Data.Fixed’

      instance Integral a => Fractional (Ratio a)

        -- Defined in ‘GHC.Real’

      instance Fractional Double -- Defined in ‘GHC.Float’

      ...plus one other

    In the first argument of ‘print’, namely ‘it’

    In a stmt of an interactive GHCi command: print it


Sample Input and Output:

Input 1:-
  val = 50
  ((x:y:[]):xs) = [[120, 30], [100,50],[60, 20]]
Output 1:-
  180.0000

Input 2:-
val = 10((x:y:[]):xs) = [[500,30]]
Output 2:- 166.6667
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160912/5b32c1ef/attachment.html>


More information about the Haskell-Cafe mailing list