I'm having trouble defining a function in Haskell. What I want to do is input a variable of type EnvV
and one of type Store
and return a State
type variable:
type Variable = String
type Z = Integer
type T = Bool
type State = Variable -> Z
type Location = Z
type Store = Location -> Z
type EnvV = Variable -> Location
search :: EnvV -> Store -> State
search envV store = envV(store)
Try matching the types:
You have EnvV
which is Variable -> Location
and Store
which is Location -> Z
And you want the output of State
which is Variable -> Z
Can you see the connection between them ? You have to eliminate Location
between them.
search :: EnvV -> Store -> State
search envV store = \x -> store (envV x)
Since you want Variable
in the output, introduce x
which denotes that. Then apply it to envV
which will give you Location
. Now apply that to store
which will give Z
. This will give you a type of Variable -> Z
which is expected by you.
This can be written more concisely:
search :: EnvV -> Store -> State
search envV store = store . envV
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments