title: Could not deduce (Dim n0)
body: <p>I want to build a Hilbert matrix using the linear package and convert it to a list of lists. While this seems an easy task the type level constraints come into my way:</p>
  <pre><code>import Linear
  import Linear.V
  import Data.Vector qualified as V
  
  -- | Outer (tensor) product of two vectors
  outerWith :: (Functor f, Functor g, Num a) =&gt; (a -&gt; a -&gt; a) -&gt; f a -&gt; g a -&gt; f (g a)
  {-# INLINABLE outerWith #-}
  outerWith f a b = fmap (\x -&gt; fmap (f x) b) a
  
  hilbertV :: forall a n. (Fractional a, Dim n) =&gt; Integer -&gt; V n (V n a)
  hilbertV n =
    let v = V $ V.fromList $ fromIntegral &lt;$&gt; [1..n]
        w = V $ V.fromList $ fromIntegral &lt;$&gt; [0..n-1]
    in luInv $ outerWith (+) w v
  
  listsFromM :: V n (V n a) -&gt; [[a]]
  listsFromM m = vToList (vToList &lt;$&gt; m)
  
  vToList :: V n a -&gt; [a]
  vToList = V.toList . toVector
  
  hilbertL :: forall a. (Fractional a) =&gt; Integer -&gt; [[a]]
  hilbertL n = listsFromM (hilbertV n)
  </code></pre>
  <p>When doing this the following error arises in the last line <code>hilbertL n = listsFromM (hilbertV n)</code>:</p>
  <pre><code>bench/Solve.hs:28:26: error:
      • Could not deduce (Dim n0) arising from a use of ‘hilbertV’
        from the context: Fractional a
          bound by the type signature for:
                     hilbertL :: forall a. Fractional a =&gt; Integer -&gt; [[a]]
          at bench/Solve.hs:27:1-56
        The type variable ‘n0’ is ambiguous
        These potential instances exist:
          three instances involving out-of-scope types
            instance GHC.TypeNats.KnownNat n =&gt; Dim n -- Defined in ‘Linear.V’
            instance Data.Reflection.Reifies s Int =&gt;
                     Dim (Linear.V.ReifiedDim s)
              -- Defined in ‘Linear.V’
            instance forall k (n :: k) a. Dim n =&gt; Dim (V n a)
              -- Defined in ‘Linear.V’
      • In the first argument of ‘listsFromM’, namely ‘(hilbertV n)’
        In the expression: listsFromM (hilbertV n)
        In an equation for ‘hilbertL’: hilbertL n = listsFromM (hilbertV n)
  </code></pre>
  <p>How can i get this to compile?</p>