开发者

Why is this code not working? (combining two test functions)

开发者 https://www.devze.com 2023-04-12 15:16 出处:网络
module Data where data Cons a = Con (a -> Bool) deriving (Show) twoCons :: Cons a -> Cons a -> Cons a
module Data where

data Cons a = Con (a -> Bool)
   deriving (Show)           

twoCons :: Cons a -> Cons a -> Cons a
twoCons (Con a) (Con b) = Con (twoCons' a b)

twoCons' :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)
twoCons' c1 c2 x = (c1 x) && (c2 x)

This code do开发者_如何学Cesn't work, with or without deriving (Show).

It's supposed to combine two tests/constraints and return a function wrapped by the third Con. The constraints might be (>1) and (<10), the outcome should be an combination of the two constraints, the type of constraint can be anything.


The problem is that there is no reasonable way to write an instance of Show for Cons (try it yourself!)

If you remove the deriving (Show) clause your code works perfectly.

0

精彩评论

暂无评论...
验证码 换一张
取 消