I'm new to Haskell and I'm still getting my head around it. I'm trying to combine two functions (isMark and isAlpha from Data.Char module in base package) as a first argument to Data.Text.filter function. What I've tried so far was:
import qualified Data.Char as C
import qualified Data.Text as T
import Data.Text (Text)
strippedInput :: Text -> Text
strippedInput input = T.filter (C.isMark || C.isAlpha) input
which doesn't work, or
strippedInput input = T.filter (C.isMark . C.isAlpha) input
but obviously it doesn't work either, as the type of C.isAlpha is Char -> Bool which then becomes an input to C.isMark which is also of type Char -> Bool so types don't match.
I'd like to achieve the "C.isMark OR C.isAlpha" logic in the predicate but because of my very limited knowledge I've run out of ideas on how to search for the solution.
The simplest is to make use of a lambda-expression:
strippedInput :: Text -> Text
strippedInput input = T.filter (\x -> C.isMark x || C.isAlpha x) input
You can furthermore make use of the fact that a function is an applicative functor, and thus work with:
import Control.Applicative(liftA2)
strippedInput :: Text -> Text
strippedInput input = T.filter (liftA2 (||) C.isMark C.isAlpha) input
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With