So let's say you have a variable n.
You want to check if its an integer, or even better yet check what type it is.
I know there is a function in haskell, isDigit that checks if it is a char.
However is there a function that checks if n is in integer, or even better, gives the type of n?
If you are using an interactive Haskell prompt (like GHCi) you can type :t <expression> and that will give you the type of an expression. or e.g.
The == is an operator for comparing if two things are equal. It is quite normal haskell function with type "Eq a => a -> a -> Bool". The type tells that it works on every type of a value that implements Eq typeclass, so it is kind of overloaded.
elem :: element -> list -> Bool. Use elem if you want to check whether a given element exists within a list.
A type variable is a way to have polymorphism by writing a single function/method that works on multiple different types of values. Here is an example in Haskell: id :: forall a. a -> a id x = x. The a in the type signature is a type variable, and as the forall implies, this function works "for all" different types.
import Data.Typeable
isInteger :: (Typeable a) => a -> Bool
isInteger n = typeOf n == typeOf 1
But you should think about your code, this is not very much like Haskell should be, and it probably is not what you want.
If you are using an interactive Haskell prompt (like GHCi) you can type :t <expression>
and that will give you the type of an expression.
e.g.
Prelude> :t 9
gives
9 :: (Num t) => t
or e.g.
Prelude> :t (+)
gives
(+) :: (Num a) => a -> a -> a
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