0

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?

Bobo
  • 165
  • 6
  • 3
    When you ask this sort of question **give us the error message**. The error messages are trying to help the programmer understand what's wrong. Even if they don't mean anything to you, they will help SO help you. And then, once you've gotten your answer, look at the error message and try to figure out how it corresponds to the explanation of your problem. That will gradually give you the ability to use type error messages to identify the problem for yourself! – Ben Nov 10 '12 at 01:21

1 Answers1

1

Your shift function is declared to return a Subst, but it really returns a list. You probably meant to wrap the Subst constructor around the list.

Then your subst function is declared to take a Subst argument, but you're calling it with a list - same issue basically.

Also your vars function 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 type a -> [String].

sepp2k
  • 363,768
  • 54
  • 674
  • 675