简体   繁体   中英

Type Error In Haskell Function

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 as vars :: a -> [String] . When I run this, I get a type error. Any ideas why?

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] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM