Maybe I'm the only one who didn't already know this, but I'd like to describe how to use GHCi within a Cabal project under development.
Say I'm working on a library foobar:
~/foobar $ find -type f
./foobar.cabal
./Data/FooBar.hs
./Setup.hs
./LICENSE
I want to write a test program, which won't go in the Cabal distribution:
~/foobar $ cat > test.hs
import Data.FooBar
main = print fooBar
^D
~/foobar $ cabal configure && cabal build
Resolving dependencies...
Configuring foobar-0.1...
Preprocessing library foobar-0.1...
Building foobar-0.1...
Registering foobar-0.1...
~/foobar $ ghci test.hs
GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 2] Compiling Data.FooBar ( Data/FooBar.hs, interpreted )
[2 of 2] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: Data.FooBar, Main.
GHCi is loading Data.FooBar into the interpreter, but I wanted to test the compiled, optimized version that was just produced by Cabal. Let's try telling it about the dist/ directory:
~/foobar $ ghci test.hs -package-conf dist/package.conf.inplace
GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 2] Compiling Data.FooBar ( Data/FooBar.hs, interpreted )
[2 of 2] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: Data.FooBar, Main.
Still no good. Seems that the existence of the file Data/FooBar.hs overrides anything in the package database. Move to another directory:
~/foobar $ mkdir test && cd test
~/foobar/test $ mv ../test.hs .
~/foobar/test $ ghci test.hs -package-conf ../dist/package.conf.inplace
GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main ( test.hs, interpreted )
Ok, modules loaded: Main.
*Main> fooBar
Loading package foobar-0.1 ... linking ... done.
"testing 123"
It works. :) For compiled code as well:
~/foobar/test $ ghc --make -O test.hs -package-conf ../dist/package.conf.inplace
[1 of 1] Compiling Main ( test.hs, test.o )
Linking test ...
~/foobar/test $ ./test
"testing 123"
شركة تنظيف فلل بالرياض تتيح لكم ما تحتاجونه من خدمات تنظيف في مختلف المنشآت بجميع المساحات والأغراض والمحتويات، إذ أن الشركة تقدم من خلال أفضل العمال والمتخصصين وبإشراف الخبراء الذين تستعين بهم الشركة للإشراف على ما يتم القيام به من مهام وخدمات وتوفير كافة سبل الراحة لعملائها الكرام من خلال ما تستعين به من وسائل ومواد ومعدات تتميز بتقنياتها المتطورة والحديثة والتي تواكب من خلالها مستلزمات العصر الحديث و للوصول إلى أفضل ما قد يتطلع له العملاء بجميع فئاتهم في ما يأملون في الوصول لها من مستوى خاص بنظافة المنشأة التي يقيمون فيها أو يعملون بها ويسعون جاهدين إلى أن تظهر بأجمل هيئة وأكمل صورة داخليا وخارجيا.
ReplyDeleteتمتع بأسعار لا مثيل لها مع شركة تنظيف فلل بالرياض
يتمتع عملاء الشركة بمزايا لا تتوافر بالشركات الأخرى إذ أن أسعارنا هي الأرخص والأفضل رغم أن خدماتنا هي الأضمن والأفضل والأكثر تميزا بالمقارنة مع كبرى الشركات المماثلة إذ أن خدماتنا وأسعارنا لا منافس لها وتتميز شركة نظافة فلل بالرياض بما توفره من عروض ذات أسعار وخصومات رائعة ومذهلة على تنظيف الفلل وتعطيرها وتعقيمها جيدا من الاوبئة والجراثيم التي توجد فى تلك المساحات من الفلل الكبيرة والصغيرة .
https://www.allsaad.com/70-2/
لمزيد من خدماتنا
شركة عزل فوم بالرياض
homeshop4u เว็บไซต์สำหรับคนรักสัตว์ สัตว์เลี้ยงยอดนิยม ดูแลสุขภาพสัตว์เลี้ยงของคุณ ติดตามได้ที่นี้ เเนะนำเทคนิค เเละทรคิในการเลี้ยงสัตว์เลี้ยงอย่างถูกวิธี การเลี้ยงสัตว์เลี้ยงให้ถูกวิธีสุขภาพสัตว์เลี้ยงให้ดีได้ง่ายๆ เเนะนำสัตว์เลี้ยงเเสนน่ารัก รอบรู้สัตว์เลี้ยงทั่วโลกในเว็บไซต์เดียว.
ReplyDeleteGutt Websäit : Tertinggi
ReplyDeleteGutt Websäit : Zonahobisaya
Gutt Websäit : Terdalam
Gutt Websäit : Terbanyak
Gutt Websäit : Profil
Gutt Websäit : Zonahobisaya
Gutt Websäit : Zonahobisaya
Gutt Websäit : One Piece
Käytän aina puoli tuntia lukiakseni tämän verkkosivuston sisältöä päivittäin kahvikupin kera.
ReplyDeleteGreat insights on using GHCi with Cabal for testing Haskell libraries! It's essential to realize how module loading can impact the testing phase. Speaking of engaging activities, I recently enjoyed playing the Slope, which sharpens problem-solving skills—similar to programming! For any beginners in Haskell, exploring GHCi alongside fun games like Slope can make learning more efficient and enjoyable.
ReplyDelete
ReplyDeletethis blog is one of my favorite thumbs up!!
ReplyDeleteyou are really a good webmaster.