I’ve written a Haskell function like so:
shift :: Subst a -> Subst a
shift (S s) = [(x, (subst s' d)) | (x,d) <- s] where
s' = [(x,d) | (x,d) <- s, null (vars d)]
With a data type like so data Subst a = S [(String,a)]
I’ve declared subst as subst :: Subst a -> a -> a and vars asvars :: a -> [String]. When I run this, I get a type error. Any ideas why?
Your
shiftfunction is declared to return aSubst, but it really returns a list. You probably meant to wrap theSubstconstructor around the list.Then your
substfunction is declared to take aSubstargument, but you’re calling it with a list – same issue basically.Also your
varsfunction probably contains a type error as well because, as I indicated in my answer to your previous question, you can’t define a meaningful function of typea -> [String].