I'm trying to resolve the following exercise of Haskell:
Define the function exists::(N-> Bool)-> N->Bool, which receives a predicate p and a natural n, and returns True if there is any number between O and n for which p is true.
Examples:
exists pair three = True
exists isGreaterThanZero O = False
This code goes before of my exists function:
{-#LANGUAGE GADTs #-}
{-# OPTIONS_GHC -fno-warn-tabs #-}
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
module Naturales where
import Prelude(Show)
data Bool where { False :: Bool;
True :: Bool
} deriving Show
{- Data Type of Natural Numbers -}
data N where { O :: N ;
S :: N -> N
} deriving Show
zero:: N
zero= O
one:: N
one = S O
two :: N
two = S one
three :: N
three = S two
four :: N
four = S three
...
This is how I programmed the requested function called exists but when i try to compile the .hs code it says
exists:: (N->Bool)->N->Bool
exists = \p -> \x -> case x of {
O -> p O;
(S y) -> if p (S y) then True else existe p y; {- Line 288 -}
}
• Couldn't match expected type ‘GHC.Types.Bool’
with actual type ‘Bool’
NB: ‘Bool’ is defined at EstudiandoRecursion.hs:(9,1)-(11,47)
‘GHC.Types.Bool’
is defined in ‘GHC.Types’ in package ‘ghc-prim-0.5.3’
• In the expression: p (S y)
In the expression: if p (S y) then True else existe p y
In a case alternative:
(S y) -> if p (S y) then True else existe p y
|
288 | (S y) -> if p (S y) then True else existe p y; |
I suppose that the logic of my function exists it's correct, but perhaps I have made syntax error writing the code.