Haskell function definition

Eleftherios

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)  
Sibi

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.

edited at
0

Comments

0 comments
Login to comment

Related

Haskell Function Definition without ->

Definition of the flip function in Haskell

Function definition in Haskell

is Haskell sensitive to order in a function definition?

Haskell function definition and arguments list

Haskell - Bind function definition parameter

Haskell function definition not working as expected

Haskell function incompatible type and definition

Haskell - Illegal literal in type error in a function definition

Haskell - Instance of Num Char required for definition of a function

Applying a function to a recursively built list within the definition of the recursive function in haskell

I'm not sure I understand the type definition of the foldl function in haskell

Haskell: Can type variables be used within function definition?

How to shorten a Haskell function definition with many equivalent patterns

how does Haskell know `xs` is a list in the function definition?

Haskell's code indentation issue in function's definition

Why piece-wise definition of a function in Haskell depends on the order they specified?

convert Ocaml/Haskell type definition to Haskell: * in definition

Function definition or variable definition?

Haskell primPutChar definition

Haskell Map definition Error

Definition of Haskell's $-Operator

Haskell: What is the definition for '{' '}' and ','?

Haskell newtype definition

Liquid Haskell: "Cyclic type alias definition" error from an inlined recursive function

Locating the function definition of a function

Clarifying numeric literal definition in haskell

Goto Definition in Emacs - Haskell mode

Default definition in subclass of Eq in Haskell