Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control export of records in Haskell?

With the following sample module:

module Exp ( initial, myval ) where
data State = State { i :: Int }
initial = State { i = 123 }
myval st = i st

After I load the module in GHCI, I can see that the State and i names have also been exported. I can get their types and use them. How do I limit the export so that only initial (a black box) and myval are exported?

like image 768
Ana Avatar asked Nov 12 '11 23:11

Ana


1 Answers

State and i are not exported, but if you load an interpreted module in ghci, then all top-level definitions of that module are in scope. To hide what you didn't export from ghci, compile the module and load the compiled module, :l Exp resp ghci Exp. Then only the exported entities are available.

like image 167
Daniel Fischer Avatar answered Nov 12 '22 07:11

Daniel Fischer