haskell-handbook icon indicating copy to clipboard operation
haskell-handbook copied to clipboard

[New topic] Modules

Open Martinsos opened this issue 3 years ago • 9 comments

  • Internal

Martinsos avatar May 04 '21 13:05 Martinsos

I covered this briefly in learn-haskell-blog-generator:

  • https://github.com/soupi/learn-haskell-blog-generator/commit/aeee32cb9fae5a8bbda6001abef4483d1479e085
  • https://github.com/soupi/learn-haskell-blog-generator/commit/379fbb03d54791deb8c1f96902ef144917fb9fa9

soupi avatar May 05 '21 12:05 soupi

@soupi thanks, these are nice explanations, they will come in handy! Besides giving extra control to the library consumer, I also found Internal modules to be the only way to test inner workings of a module.

Martinsos avatar May 06 '21 10:05 Martinsos

Haskell school will have a section on module: https://github.com/haskellfoundation/HaskellSchool/pull/28

soupi avatar Nov 04 '21 08:11 soupi

Haskell school will have a section on module: haskellfoundation/HaskellSchool#28

Thanks! They seem to be focusing on basic workings of modules -> I instead hope to focus on organizing them from the higher level and using Internal as a mechanism.

Martinsos avatar Nov 08 '21 14:11 Martinsos

I started some work here https://github.com/wasp-lang/haskell-handbook/blob/master/module-tree-api.md .

Martinsos avatar Nov 08 '21 14:11 Martinsos

In that case, I've covered internal modules in the book, and Gabriella suggests one way to organize modules (which is a bit different than what I've seen in many places, but definitely good general advice).

soupi avatar Nov 08 '21 17:11 soupi

Aha I haven't noticed you covered that in your book, that is great! Some thoughts:

  • If I am developing module X, I usually don't put everything into X.Internal and then re-export only "public" stuff in the X. Instead, I usually start writing module X, and then when I figure out something is internal/private, I move it to X.Internal, at the end ending up with "private" stuff being in X.Internal and "public" stuff being in X, with potentially re-exporting some things from X.Internal if needed. I wonder if there is a significant difference between the two approaches? I guess not?
  • I found Internal modules to be crucial for testing, maybe that is also worth mentioning. I don't know any other way to test "private" functions.

Martinsos avatar Nov 09 '21 09:11 Martinsos

Regarding vertical vs horizontal -> I also prefer vertical approach, as Gabriella suggests. I figured that out for the first time while working on AngularJS projects some time ago and have stuck with it since then. I usually call that "feature-based" organization vs "type-based" organization, based on this article: https://johnpapa.net/angular-growth-structure/ .

Martinsos avatar Nov 09 '21 09:11 Martinsos

I wonder if there is a significant difference between the two approaches? I guess not?

When separating to public and private modules one issue that can crop up is cyclic dependencies - it's reasonable for public to depend on private, but the other way around is also likely. Especially for things like data type definitions.

soupi avatar Nov 09 '21 11:11 soupi