morloc-project / morloc

A typed, polyglot, functional language
GNU General Public License v3.0
195 stars 4 forks source link

cpp example fails missing module "conventions" #24

Open stain opened 3 months ago

stain commented 3 months ago

I can't run the second example in the README as I get an error:

(base) stain@xenamint:~/src/morloc$ cat example-1.loc 
module sos (*)

import cppbase (fold, map, add, mul)

square x = mul x x
sumOfSquares xs = fold add 0 (map square xs)

(base) stain@xenamint:~/src/morloc$ morloc make -o nexus example-1.loc

CannotLoadModule: module 'conventions' not found among the paths: [ /home/stain/.morloc/src/morloc/conventions.loc
, /home/stain/.morloc/src/morloc/conventions/main.loc
, /home/stain/.morloc/src/morloc/plane/morloclib/conventions.loc
, /home/stain/.morloc/src/morloc/plane/morloclib/conventions/main.loc
, conventions.loc
, conventions/main.loc ]
current module: Just ("/home/stain/.morloc/src/morloc/plane/morloclib/cppbase/main.loc",MV {unMVar = "cppbase"})
import module: MV {unMVar = "conventions"}
arendsee commented 3 months ago

Thanks for the report, I've added a install statement for the morloc module conventions to the Dockerfile. I should probably include that module in the base morloc container, but adding it here should fix the problem.

arendsee commented 3 months ago

Reopening. You worded your question very clearly but I clearly didn't read it properly. I'll get back with you in a moment.

arendsee commented 3 months ago

You can address the current error by installing the conventions module with morloc install conventions.

But after installation, I suspect you will hit a second error. This is an old example from before I added typeclasses. Back then, there was just one mul function that multiplied integers. Now mul is one function in a typeclass that includes instances for the integer and real types. But the compiler does not know which function the user wants. So you will need to add a top-level signature for each function, as below:

module sos (*)

import cppbase

square :: Real -> Real
square x = mul x x

sumOfSquares :: [Real] -> Real
sumOfSquares xs = fold add 0.0 (map square xs)

I will clarify all this in the README.