Wednesday, July 08, 2020

How to use a personal library in another project with Stack? (Haskell)



In Haskell, Haskell tool stack is quite difficult at least to me. For example, I want to use a personal library (a pre-release version of a Hackage package) from a stack project  in another stack project. Conceptually, it is simple, but it takes a bit long to find a solution from Stackoverflow.

Here is a summary.

In stack.yaml

packages 
- '.'
- path-to-a-stack-project-directory-containing-your-personal-library

In packages.yaml

dependencies:
- your-personal-libary

Then run 

$ stack build

This will solve your need. How easy it is after one knows how to do it! But I worry how difficult Haskell newbies may feel. 


Saturday, July 04, 2020

Switching between my office and my home working on the same working branch (Git, GitHub)

I am still a newbie to Git and GitHub. I have recently started using the notion of branches. In my office, I work on master and working branches, and I always push them to GitHub before I get back home. At my home, I work with my home computer. So I clone the GitHub repository. What I want to do is to work on the working branch and to push whatever I work on at home later.

This is what I need to do at home for this purpose.

$ git clone https://github.com/kwanghoon/polyrpc

$ cd polyrpc

$ git branch -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/working_erasure

$ git checkout origin/working_erasure
주의: 'origin/working_erasure' 체크아웃하기.

지금 'HEAD가 분리된' 상태입니다. 이 상태에서는 여기저기 돌아보고,
실험적으로 바꾸고 커밋하더라도, 체크아웃할 수 있는 다른 브랜치에
영향을 미치지 않고 변경 사항을 잃어버릴 수 있습니다.

커밋을 유지하는 브랜치를 새로 만드려면, (지금이든 나중이든) 체크아웃
명령을 다시 하면서 -b 옵션을 사용하면 됩니다. 예를 들어:

  git checkout -b <새-브랜치-이름>

HEAD의 현재 위치는 1597a06 Added some options to switch between typed and untyped runnings; Default is the typed running; Bugs in the erasure pass

$ git branch -a 
* (HEAD origin/working_erasure 위치에서 분리됨)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/working_erasure

$ git checkout working_erasure
'working_erasure' 브랜치가 리모트의 'working_erasure' 브랜치를 ('origin'에서) 따라가도록 설정되었습니다.
새로 만든 'working_erasure' 브랜치로 전환합니다

$ git branch
  master
* working_erasure

$


Monday, April 27, 2020

Another quick guide for Haskell Stack

When you have Main.hs with no stack project, how can you build and run it?


In old days, I used Hugs or GHCi just to load a single Haskell file without any fancy project configurations. Sometimes the Haskell file required me to install some extra libraries such as network. Then I had only to give Hugs or GHCi an option to inform it of a  path where the libraries reside. 

How can you do this with Haskell Stack? This is the topic of this article. I found out it is easy!


$ ls 
Main.hs

$ stack init

$ stack ghci --no-load
Prelude> :l Main
Main.hs:3:1: error:
          Could not find module 'Network.Socket'
...
Prelude>:q

$ stack install network

$ stack ghci --no-load
Prelude> l: Main
Ok, one module loaded.
*Main>


This is it!! Isn't it surprisingly simple? But why does nobody explain it to me? :)


Saturday, March 28, 2020

How to count the number of lines of code?

How to count the number of lines of code?

You can do it simply by combining a few Linux tools. Suppose you are in a root directory that contains many recursive subdirectories and have Haskell (.hs) source files.

$ find . -name "*.hs" -exec wc \{\} \; | cut -c 1-8 | awk 'BEGIN {sum=0} {sum=sum+$0} END {print sum}'

END.