2009/7/22 Matthias Görgens <[email protected]> > I need to take some elements from the front of a list. However the > criteria are somewhat complex. > > > walk f [] = [] > > walk f (x:xs) = case f x > > of Just g -> x : walk g xs > > Nothing -> [] > > For each item the `predicate' f either returns Nothing, when it thinks > we should not take any more elements, or return Just another > `predicate' to apply to the next element. > > However the type system does not like my function. How can I mollify it?
At a quick glance it looks to me like the type of f is infinite. Something like: f :: a -> Maybe (a -> Maybe (a -> ...)) When I've seen people solve similar problems in the past they have introduced a data type to hide the infinite type. See for example, the solution to defining fix: http://blog.plover.com/prog/springschool95-2.html I didn't actual read that article, but it appears to explain the technique. Jason
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
