# [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
Tue Sep 13 03:09:14 UTC 2016

```Thanks Jack it works.

On Tue, Sep 13, 2016 at 12:01 AM, Jack Henahan <jhenahan at me.com> wrote:

>
> The inferred type of findLoot is
>
> findLoot :: (Integral a, Fractional a) => a -> [[a]] -> a
>
> It's impossible to satisfy those constraints.
>
> Rewriting like this does what you want, but there's likely a cleaner way
> to express this algorithm.
>
> findLoot :: (Integral a, Fractional b) => a -> [[a]] -> b
> findLoot val [] = 0.0
> findLoot val ((x:y:[]):xs) | val == 0 = 0.0
>              | val < y = ((fromIntegral val) * (fromIntegral x)) /
> fromIntegral y
>              | val > y = fromIntegral ((div val y)*x) + (findLoot (mod val
> y) xs)
>
>
>
> Balraj Singh <erbalrajs at gmail.com> writes:
>
> > Hi,
> >
> 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
>
>
> --
> Jack
>
-------------- next part --------------
An HTML attachment was scrubbed...
```