Better way of inserting directories in Haskell modules - haskell

I am writing a (actually my first) largish program in Haskell and am trying to break up my program into modules, so that it might be easier to maintain. In Haskell, the module names seem to be dependent upon the directory structure. This is perfectly fine till I have to embed another layer of directory structure for the program. Ill give a very simple example below:
Let us say that we are starting out with a Haskell program with the following directory structure.
Names in [square brackets] represent directories,
names in {curly braces} represent modules,
names in (normal brackets) represent file names associated within the modules
[src]
- (Main.hs) {Main}
- (PRBS.hs) {PRBS}
- [Hardware]
- (DataDef.hs) {Hardware.DataDef}
- (ShiftRegister.hs) {Hardware.ShiftRegister}
This is all fine. I can import everything I want wherever I want it. However, now say I want to create another level of abstraction, like so:
[src]
- (Main.hs) {Main}
- [Firmware]
- (PRBS.hs) {Firmware.PRBS}
- [Hardware]
- (DataDef.hs) {Firmware.Hardware.DataDef}
- (ShiftRegister.hs) {Firmware.Hardware.ShiftRegister}
Notice now that the names of all modules in Hardware have changed. I now have to change the module names within each file, and in all the other files where the files are imported. The three files I have shown in just an example. If the directory structure ends up having hundreds of files with tens of embedded directories, then it might become impossible to maintain code. Furthermore, if at any point, I want to copy a directory (and its subdirectories at a particular point in the current directory system), I need to figure out all the previous directories that come before it, and manually change the module names within each file.
Since Haskell is used in several large projects, I am very certain that I am missing something here. Any help in getting me out of this quagmire will be greatly appreciated!

If you have perl and bash and find and all that, you can do something like this:
find Firmware/Hardware/ -name '*.hs' -exec perl -i.bak -pe \
's/^module (Hardware\.\S+)/module Firmware.$1/' \
{} \;
diff Firmware/Hardware/DataRef.hs{,.bak}

Related

Need Help in a lot of things

In my company
I need to organized all files and folder from ALL servers into a Text, basally Inside the Platform Smartsheet.
I was writing all the names of the files and folder by hand, then, I realized that exist so many files, like crazy, will never end write them all!
So I tried to find an easy solution, and I find here a code in Windows that help a lot:
Code: Tree /f /a >file.txt (I try to convert txt to CSV online, but if I changed the code to this in the end: >file.csv also works xD don't need to convert)
Anyway, I need a solution to have in that code the SIZE of all files and folders, the boss wanna know the size of the all files too.
Then, other problem as, If I import to Smartsheet / Excel the tree effect (this is important the tree) don't works very well, and I'm crazy to figure out a way to do something like this: The tree effect while importing to smartsheet / excel need automatic have a hide / show lines (with symbol + and -). Like this photos:
with + : https://ibb.co/cLjQLpF
with - : https://ibb.co/g3Y2pps
To explain better: + means Folder and I want all folder (+) in a tree.
If exist a program that do this automatic much better, but I don't find no one.
Thanks
regards

How to diff files/folders in Gradle?

I need to write a script in Gradle that takes as an input 2 folders.
Both folders contain <1000 files (mostly images) with reasonably similar structure.
The output should be a list of files that changed and what kind of difference it is (added file/deleted file/changed file).
Edit: Heres a sample script https://gist.github.com/igormukhin/71d780c4274336eeb297 . The only problem is that it compares by timestamp.
I have recently coded up something similar to what you are asking for: DirectoryDifferenceCollector; however, it actually compares the contents of the files (as a hash) and not the timestamp. I would be willing to update it to accept a configurable strategy if that would suit your needs, or you can just use the concepts involved.
Basically it scans both directories and determines the missing files in both A and B and then it also determines which files are common to both directories, but have different content.
The results are collected in a DirectoryDifference object with the respective file paths for each category.
I'd be tempted to use diff:
def process = 'diff x y'.execute()
You can then access the output of the command as text:
println process.err.text
println process.in.text
And get the exit status via:
int status = process.waitFor()
Many common operating systems will come with diff installed, but Windows probably does not.

Adding files to sourcecontrol on linux using cleartool

I have a file that i want to add to sourcecontrol on linux using cleartool .
I've followed the IBM documentation for this, i've tried this:
cleartool mkelem testScript.sh
I got an error: Can't modify directory "." because it is not checked out.
I also would like to know how can i checkout/checkin files or directories and setting activities.
You need to checkout the parent folder first.
cd /path/to/file/
cleartool mkact newfile
cleartool checkout -c "add file" .
cleartool mkelem testScript.sh
cleartool checkin -nc
The cleartool mkact would work if you are in an UCM view.
It will create and set a new activity, which will record the files and folder you will modify.
Here, the new activity newFile will record the new version of the parent folder, as well as the version 0 and 1 of the file.
You should create separate questions for .. separate questions...
Going back to the original - the reason why it isn't working is, as VonC has pointed out, you haven't checked out the parent of the file. Remember, when you run "cleartool mkelem", you are about to modify the contents of the parent directory (. in this case) by adding a new "pointer" to the element you're now creating. As with everything else in clearcase, when you want to modify the contents of an element, you have to check it out first.
One of ClearCase's greatest strength (and hardest to wrap one's head around) is the concept of an "element", IMO. "Everything" behaves similarly with an element. Making any change to an "element" (file or directory) means you have to check it out first to make that change.
In the case of a file, that's easy to grasp - you're just editing lines in a file. For a directory, it's almost as easy - you can think of a directory as just a list of pointers to data blobs. We make the name of the blob something convenient we can remember (like foo.java or myapplication.cc or README.md). But we can also change the name of the pointer (even though it points to the same data blob) by renaming a file. We can remove the pointer to the blob without impacting the blob itself by using "rmname". That's essentially what "rmname" does.
In ClearCases' case, the mkelem command is a little bit special - it creates the initial datablob, and adds a pointer to that datablob in the current directory (kind of does 2 things at once).

Cannot zip files with the same name?

I could not believe this: it seems that the zip specification does not allow two different files with the same file name going into one zip file.
In my case I use an external file to specify all the files I wanna zip.
This could look like this:
../Website1/favicon.ico
../Website2/favicon.ico
and there we are, that's not possible, despite keeping the directory structure. You would expect the name to be <../Website1/favicon.ico> rather than but that does not seem to be the case, I get:
"Invalid ZIP request (cannot repeat names in Zip file)"
with WinZip. I tried the same with 7Zip - same result.
Strangely googling did not show many hits that really fit but those I found seem to confirm my findings. That's hard to believe since this limitation is very severe. I actually struggle to understand why this did not hit me a couple of decades earlier.
Am I overlooking something very basic here?
To be precise:
Adding these two files:
C:\Temp\Website1\FavIcon
C:\Temp\Website2\FavIcon
results in a single file; the last Add wins...
This however:
Website1\FavIcon
Website2\FavIcon
results in a zip file that contains both files.

save MATLAB code file along with results in one folder?

I'm processing a data set and running into a problem - although I xlswrite all the relevant output variables to a big Excel file that is timestamped, I don't save the code that actually generated that result. So if I try to recreate a certain set of results, I can't do it without relying on memory (which is obviously not a good plan). I'd like to know if there's a command(s) that will help me save the m-files used to generate the output Excel file, as well as the Excel file itself, in a folder I can name and timestamp so I don't have to do this manually.
In my perfect world I would run the master code file that calls 4 or 5 other function m-files, then all those m-files would be saved along with the Excel output to a folder names results_YYYYMMDDTIME. Does this functionality exist? I can't seem to find it.
There's no such functionality built in.
You could build a dependency tree of your main function by using depfun with mfilename.
depfun(mfilename()) will return a list of all functions/m-files that are called by the currently executing m-file.
This will include all files that come as MATLAB builtins, you might want to remove those (and only record the MATLAB version in your excel sheet).
As pseudocode:
% get all files:
dependencies = depfun(mfilename());
for all dependencies:
if not a matlab-builtin:
copyfile(dependency, your_folder)
As a "long term" solution you might want to check if using a version control system like subversion, mercurial (or one of many others) would be applicable in your case.
In larger projects this is preferred way to record the version of source code used to produce a certain result.

Resources