We can use a type synonym for function definitions, for example.
type FuncDef = Int -> Int -> Int
This allows us to write a long definition of a function each time.
Using:
someFunc :: FuncDef -> Int
Instead
someFunc :: (Int -> Int -> Int) -> Int
which is more readable and less code.
Simple types of algebraic data are straightforward and easily perform pattern matching, etc., for example.
data AType = X | Y | Z Int matchType :: AType -> Bool matchType X = .. matchType Y = .. matchType (Z _) = ..
Since I look more at Haskell data types, I found that when defining a new type, we can have a function definition in the data constructor.
data MyType ab = X | Y (a -> b)
This is a bit perplexing to me and have not seen many examples of this. In a sense, the idea of a higher-order function, where a function can take another function as an argument, is similar to this situation, except that it applies to a data type. The Haskell wiki doesn't say much about "defining a high-order data type." I understand that I can be mistaken in all these terms, so please correct me and point me more. I really want to see the specific use of this. Thanks!
matchMyType :: (MyType ab) -> Bool matchMyType X = .. matchMyType Y ?? = ..
types pattern-matching haskell
vis
source share