Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Difficulties with functors and abstract types

$
0
0

@glennsl has it right, you just need to remove the type annotations on the modules.

module type FunctorType = {
  type a
  // "type a = string" works but I want to set the type in MyMod
  let injectedRun: a => unit
}

module Functor = (R: FunctorType) => {
  let runInjectedRun = x => R.injectedRun(x)
}

module MyMod = {
  type a = string // this is where I want to set the type
  let injectedRun = (x: a) => Console.log(x)
}

module MyModInt = {
  type a = int // this is where I want to set the type

  let injectedRun = (x: a) => Console.log(x)
}

module NewMod = Functor(MyMod)
module NewModInt = Functor(MyModInt)
NewMod.runInjectedRun("hello")
NewModInt.runInjectedRun(42)

Playground link: ReScript Playground


Viewing all articles
Browse latest Browse all 2592

Trending Articles