The PAKCS REPL consider something undefined, but the module defining it is loaded

58 views Asked by At

The problem

My code includes a module called Tests which defines the following:

broken :: SetRBT Int
broken = insertRBT 1 $ emptySetRBT (<)

I can evaluate broken in the REPL:

All> broken
RedBlackTree.RedBlackTree (_impl#==#Prelude.Eq#Prelude.Int) (_impl#==#Prelude.Eq#Prelude.Int) (_def#<#Prelude.Ord (_inst#Prelude.Ord#Prelude.Int)) (RedBlackTree.Tree RedBlackTree.Black 1 RedBlackTree.Empty RedBlackTree.Empty)
All>

I cannot, however, evaluate the RHS of broken's definition:

All> insertRBT 1 $ emptySetRBT (<)

PAKCS_Main_Exp.curry, line 3.18: Error:
    Undefined type RedBlackTree.RedBlackTree
ERROR occurred during parsing!
All>

Or so I believed, until I tried attaching a type signature:

All> insertRBT 1 $ emptySetRBT (<) :: SetRBT Int
RedBlackTree.RedBlackTree (_impl#==#Prelude.Eq#Prelude.Int) (_impl#==#Prelude.Eq#Prelude.Int) (_def#<#Prelude.Ord (_inst#Prelude.Ord#Prelude.Int)) (RedBlackTree.Tree RedBlackTree.Black 1 RedBlackTree.Empty RedBlackTree.Empty)
All>

I'm fine with having to attach type signatures when needed, or more generally, to do whatever the error messages suggest I should do. But how would I know to interpret the above error message as meaning "you've got to attach a type signature"? More generally, what does that type error even mean, given that (see below) RedBlackTree is loaded?

What I am loading

Each time I start PAKCS I run :l All. That loads a module which reads, in relevant part,

module All ( module M
           ) where

import FiniteMap as M
import SetRBT as M
import RedBlackTree as M
import Tests as M

That idiom lets me load all the things that I need (there are others) without producing a long prompt.

If I run :modules it looks like RedBlackTree should be defined:

All> :modules
Currently loaded modules:
All                       (loaded from ./.curry/pakcs/All.pl)
Prelude                   (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/Prelude.pl)
FiniteMap                 (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/FiniteMap.pl)
SetRBT                    (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/SetRBT.pl)
RedBlackTree              (loaded from /home/jeff/logic/curry/install/pakcs-2.0.2/lib/.curry/pakcs/RedBlackTree.pl)
Tests                     (loaded from ./.curry/pakcs/Tests.pl)
All>
1

There are 1 answers

1
Sergio Antoy On

You must tell the interpreter to add referenced modules.

All> :add RedBlackTree SetRBT

... some messages ...

All SetRBT RedBlackTree> insertRBT 1 $ emptySetRBT (<)

and it will work.