I have the following snippet out of an Interpreter:
type Ident = String
type Value = Int
type State = Ident -> Value
iniState :: State
iniState = \ident -> error "internal error initial state"
updateS :: State -> (Ident, Value) -> State
updateS s (ident, val) ident' | ident' == ident = val
| otherwise = s ident'
where does the ident’ in the pattern of updateS come from?
The third argument is from the
Identargument to the function in the typeState.Using
typedefines a synonym for another type (quite literally a synonym). In other words, the following type signatures are all the same:(You could also replace
IdentwithStringandValuewithIntto do a full expansion.)The last one makes it clear that
updateScould take 3 parameters: a functionIdent -> Value, a pair(Ident, Value)and a singleIdent.