[Haskell-beginners] Could not deduce (Frame a r0) arising from a use of `len'

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Fri Sep 30 14:18:14 UTC 2016


Hello I try to write something like this

{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}

module Hkl.Frame
       ( Frame(..)
       , frames
       , frames'
       ) where

import Pipes
import Control.Monad

class (Frame a r) where
  len :: a -> IO (Maybe Int)
  row :: a -> Int -> IO r

frames :: (Frame a r) => Pipe a r IO ()
frames = do
  d <- await
  (Just n) <- lift $ len d
  forM_ [0..n-1] (\i' -> do
                     f <- lift $ row d i'
                     yield f)


But when I try to compile this I get this error message.


    Could not deduce (Frame a r0) arising from a use of `len'
    from the context (Frame a r)
      bound by the type signature for
                 frames :: Frame a r => Pipe a r IO ()
      at src/Hkl/Frame.hs:17:11-39
    The type variable `r0' is ambiguous
    Possible fix: add a type signature that fixes these type variable(s)
    In the second argument of `($)', namely `len d'
    In a stmt of a 'do' block: (Just n) <- lift $ len d
    In the expression:
      do { d <- await;
           (Just n) <- lift $ len d;
           forM_
             [0 .. n - 1]
             (\ i'
                -> do { f <- lift $ row d i';
                        .... }) }


What should I do in order to solve this problem.

Thanks


Frederic


More information about the Beginners mailing list