Search code examples
frege

“Return type is incompatible” / Bad native declaration module error on applicative instance


I’m reading the book "Haskell Programming from first principles" by Christopher Allen and Julie Moronuki and try to implement the code and examples in Frege.

Unfortunately, I run into compile errors on module level (in the eclipse editor) for the following code (Chapter 17 - Applicative; Chapter Exercises).

The error states the following:

Multiple messages at this line. -The return type is incompatible with PreludeMonad.CApplicative<Exercises17.TThree<a,b,? >>.ƒpure(Lazy<b>) -Java compiler errors are almost always caused by bad native declarations. When you're sure this is out of the question you've found a compiler bug, please report under https://github.com/frege/frege/issues and attach a copy of /Users/dkm/frege-workspace/frege_programming/bin/chapter17/Exercises17.java -The parameterized method <b, a, b>pure(Monoid.CMonoid<a>, Monoid.CMonoid<b>, Lazy<b>) of type Exercises17.IApplicative_Three is not applicable for the arguments (Monoid.CMonoid<a>, Monoid.CMonoid<b>, Lazy<b>)

I tried the same code in Haskell, where I get no errors.

Reducing the code with the "undefined"-keywords did not solve the issue, so there seems to be some other problem with the structure of the instance itself.

data Three a b c = Three a b c

instance Functor (Three a b) where
  fmap f (Three x y z) = Three x y (f z)

instance (Monoid a, Monoid b) => Applicative (Three a b) where
  pure x = undefined
  (Three a b f) <*> (Three c d x) = undefined

You can find the above code and other similar (failing as well as correctly compiling) examples as well here: https://github.com/elrocqe/frege_programming/blob/15e3bc5c4748055dc7dc640677faa54d8e9539e3/src/chapter17/Exercises17.fr#L80

The applicative-instance I’m going for should eventually look like this:

instance (Monoid a, Monoid b) => Applicative (Three a b) where
  pure x = Three mempty mempty x
  (Three a b f) <*> (Three c d x) = (Three (mappend a c) (mappend b d) (f x))

As it works in Haskell, the expected result would be for it to compile in Frege too. Similar examples do compile correctly in Frege as well. (see repo above)

Can anybody give me a hint on what’s the issue here and how to fix it?

Thanks a lot in advance.


Solution

  • You must be using an outdated Frege compiler.

    I suggest you get the latest compiler here: https://github.com/Frege/frege/releases/tag/3.25alpha

    (I just tried the "Three" example, and it compiled ok)