Babra Cunningham
Babra Cunningham

Reputation: 2967

Monadic operations within data type?

I've come across the use of :>>= in the Haxl library that I am using. I'm unsure how this is different from the >>= operator?

For example:

data MyType a = MyType a :>>= (a -> Int)

What exactly is this operation doing in MyType?

This is the context of it's using in Haxl:

newtype GenHaxl u a = GenHaxl { unHaxl :: Env u -> IORef (RequestStore u) -> IO (Result u a) } --|| u is the env, a is the result

data Result u a
  = Done a
    | Throw SomeException
    | Blocked (Cont u a)

data Cont u a
  = Cont (GenHaxl u a)
    | forall b. Cont u b :>>= (b -> GenHaxl u a)
    | forall b. (Cont u (b -> a)) :<*> (Cont u b)
    | forall b. (b -> a) :<$> (Cont u b)

Upvotes: 0

Views: 57

Answers (1)

jakubdaniel
jakubdaniel

Reputation: 2223

It is just a constructor for the type Cont u a in form of an operator. It is defined in the piece of code you included in the question.

Cont u a

is either

Cont (GenHaxl u a)

or

forall b. (:>>=) (Cont u b) (b -> GenHaxl u a)

or

forall b. (:<*>) (Cont u (b -> a)) (Cont u b)

or

forall b. (:<$>) (b -> a) (Cont u b)

the last three cases being recursive as they mention Cont u .... Further in the code there is toHaxl which folds Cont and its symbolic structure into actual values by interpreting :>>=, :<*>, and :<$> with application of the associated >>= (or >=>) etc.

Upvotes: 1

Related Questions