plinth — third look

using GNU Core utilities to parse code.

50x50
3 min readAug 8, 2024

Maybe fourth — who remembers! so its the next a bit strange, I know!

So! loooking back, we are hacking Open Source to figure out what the hell is a Contribution Ladder and how do I as a random hacker get to become a pro. One part of the process is learning collaborative building! Know thy git! Look through the Issue tracker, find one and adopt! And here is our issue — we looked at the projects docs and are figuring out what to do next.

Recall that our task here was recommended by a developer: build Arbitrary instances for the Types the module exports. We looked at the .cabal file and found that the module is indeed very modular and going forth requires asking several questions first.

How do I know when a module exports a type?

Haskell has three basic ways to declare a new type:

  • The data declaration, which defines new data types.
  • The type declaration for type synonyms, that is, alternative names for existing types.
  • The newtype declaration, which defines new data types equivalent to existing ones.
    For example, like so:
// In this example, the `MyType` type is explicitly exported from the `MyModule` module.
module MyModule (MyType) where
data MyType = MyType Int

Lets see if there is anything similar to this in the code we are looking at:

whoa?! 🧐

Its one file and there’s so much stuff!

“Types and functions” — 🤔 which is which?

There are some conventions and best practices that can help you distinguish between types and functions when importing modules:
When importing a module, you can use the module keyword to specify which parts of the module to import.

import MyModule (MyType, myFunction)

In this example, ScriptForEvaluation is likely a type, and serializedScript is likely a function; I am confused!

yes, it is!

Ah the sweet a-ha moment! This gives me something to tell apart Types from functions!

Making a list of Types that is exported by a Haskell module.

I should definitely try VSCode or set up my nvim better — with “jump to definition” navigation option would help so much with context switching!

Meanwhile I thought of how to make the process more programmatic — I sure can jump from file to file to find where each type is defined, but where is the guarantee that I miss one? There’s none, so there’s gotta be another way.

First, how about testing AI bash scripting capabilities?

after some messing about with grep

Wow! Certainly its not the answer but a step closer and a good map of whats going on! I’m not going to put bash code here and leave it a fun exercise for the reader to generate the bash script.

Are there tools about Code Coverage that can be used to highlight which types need property testing?

But this brings me to a bigger question! There should be some Haskell functionality to do this!

What’s Next?

Now that I’ve found the existing implementation, I’m left wondering… what’s next? The plot thickens, and I’m eager to explore the next twist in this coding adventure.

Stay tuned for the next installment of this hacking adventure!

--

--