[Haskell-cafe] About the return type

Brent Yorgey byorgey at seas.upenn.edu
Sat Jul 11 15:33:00 EDT 2009


On Thu, Jul 09, 2009 at 10:57:19AM -0400, xu zhang wrote:
> I have trouble in returning a list of Figures. I want return a type of m
> (Maybe [Figure IO]), but the type of dv_findFigure is :: a -> Point -> s
> (Maybe (Figure s)). How can change the code below to get a s (Maybe [Figure
> s])?
> Thank you in advance!
> 
>  dv_findFigure :: a -> Point -> s (Maybe (Figures))
>  fig_contains :: fig -> Point -> m Bool
>  anc :: Point
> do
>                      fs <- dv_getSelFigs dv
>                      fs' <- filterM (`fig_contains` anc) fs
>                      f <- case fs' of
>                         [] -> dv_findFigure dv anc
>                         fig : _ -> return $ Just fig
>                      case f of
>                        Just f' -> tool_dragtrack self f'
>                        Nothing -> dv_clearSel dv >> tool_areatrack self
> 
>   Couldn't match expected type `Figure m'
>            against inferred type `[Figure IO]'
>       Expected type: m (Maybe (Figure m))
>       Inferred type: m (Maybe [Figure IO])
>     In the expression: return $ Just fs
>     In a case alternative: fig : _ -> return $ Just fs

I'm not sure what you're trying to do here, and the code you gave does
not match the error message (the error message cites the code 'fig : _
-> return $ Just fs', but the code you gave has a line 'fig : _ ->
return $ Just fig'.)  If you still need help, can you provide a more
detailed explanation of what this code is supposed to do, and an
up-to-date version of the code and error message?

-Brent


More information about the Haskell-Cafe mailing list