Answer the question
In order to leave comments, you need to log in
Pattern matching ( Haskell )?
there is a function
substitute :: Char -> Char -> String -> String
substitute xy [] = []
substitute xy (h:hs) = if h == x than y : substitute xy hs
else h : substitute xy hs
which replaces in string some letters x to letters y , tried to remake it for pattern matching so if let's say the head of the list matches the letter x then he would change it, otherwise he would go further
substitute :: Char -> Char -> String -> String
substitute xy [] = []
substitute xy (x:hs) = y : substitute xy hs
else _ : substitute xy hs
failed
Answer the question
In order to leave comments, you need to log in
In Haskell, unlike, for example, Wolfram Mathematica, in the list of samples within one case, each variable can be used only once.
In fact, samples are a short form of writing a system of projections for product-types and parsing cases for sum-types.
For example,
substitute x y [] = ...
substitute x y (h:hs) = ...
is a shorthand notation (by the way, the "simplified" Haskell, to which ghc leads the code before compilation, just uses such a representation)substitute x y z = case z of
[] -> ...
(h:hs) -> ...
or, if hyperbolized ,func x x = ...
when x :: a -> b
? Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question