Does the >>= operator not take a function?

78 views Asked by At

I'm working on a side project and I'm using Hopac for the first time. I ran into an odd (to me) compilation issue that I haven't been able to grok. I suspect that I'm the problem here, and not Hopac.

The program is supposed to be a simple console app that consumes notifications from various services. Here's the problematic module:

module Provider

open System
open System.IO
open Hopac
open BitThicket.NotificationHelper.Core
open BitThicket.NotificationHelper.Providers

let defaultProviderTypes =
    [| typeof<GitHub.GitHubNotificationProvider> |]

type Provider = {
    getCh : Ch<Providers.INotification seq>
}

let giveLatest ch latest =
    Ch.give 

let start config logger (providerType:Type) = Job.delay <| fun () ->
    let providerImpl = Activator.CreateInstance(providerType) :?> Providers.INotificationProvider
    let p = { getCh = Ch() }

    let rec server = 
        let latest = providerImpl.GetLatestNotificationsAsync(None) |> Job.fromAsync 
        latest >>= Ch.give p.getCh // error here
    }

    Job.start server

In this case, the compiler complains: Expecting a type supporting the operator '>>=' but given a function type. You may be missing an argument to a function.

Similarly, if I use a slightly different syntax:

// ...
    let rec server =
        let latest = providerImpl.GetLatestNotificationsAsync(None) |> Job.fromAsync
        latest >>= fun l -> Ch.give p.getCh l // error here
// ...

In this case, the error is: This function takes too many arguments, or is used in a context where a function is not expected.

I asked haf about his in slack, and his suggestion was to check for alternative definitions of >>=. The tooling doesn't really do much to help me figure that one out, but the only namespace/module I have opened that defines >>= is Hopac (the BitThicket ones are just trivially simple namespaces with some type definitions in them).

What am I doing wrong here?

1

There are 1 answers

0
Fyodor Soikin On BEST ANSWER

I'm looking at the source code, and I see that the bind operator is actually defined in Hopac.Infixes, not in Hopac.