The program below, diagram1.hs, is from the PDF "What I Wish I Knew When Learning Haskell" by Stephen Diehl; see the chapter titled "Graphics".
I am using MacOS Ventura 13.4.1 (c) (22F770820d)
My shell is zsh
The project1 folder was completely empty except for file, diagram1.hs
import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine
sierpinski :: Int -> Diagram SVG
sierpinski 1 = eqTriangle 1
sierpinski n =
s
===
(s ||| s) # centerX
where
s = sierpinski (n - 1)
example :: Diagram SVG
example = sierpinski 5 # fc black
main :: IO ()
main = defaultMain example
-- $ runhaskell diagram1.hs -w 256 -h 256 -o diagram1.svg%
On reddit.com, a user suggested:
One option would be:
Install stack:
curl -sSL https://get.haskellstack.org/ | sh
Prepend
stack exec --package diagrams --
to the command you have there:stack exec --package diagrams -- runhaskell diagram1.hs -w 256 -h 256 -o diagram1.svg
His step 1 resulted in this:
admin@admins-MacBook-Pro-2 haskellProjects % curl -sSL https://get.haskellstack.org/ | sh
Stack version 2.11.1 already appears to be installed at:
/Users/admin/.ghcup/bin/stack
Use 'stack upgrade' or your OS's package manager to upgrade,
or pass '-f' to this script to over-write the existing binary, e.g.:
curl -sSL https://get.haskellstack.org/ | sh -s - -f
To install to a different location, pass '-d DESTDIR', e.g.:
curl -sSL https://get.haskellstack.org/ | sh -s - -d /opt/stack/bin
admin@admins-MacBook-Pro-2 haskellProjects %
His step 2 resulted in this:
admin@admins-MacBook-Pro-2 project1 % stack exec --package diagrams -- runhaskell diagram1.hs -w 256 -h 256 -o diagram1.svg
ghc: panic! (the 'impossible' happened)
(GHC version 8.6.5 for x86_64-apple-darwin):
Prelude.chr: bad argument: 2650800131
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug
Error: [S-6374]
While building simple Setup.hs (scroll up to its section to see the error) using:
/Users/admin/.ghcup/ghc/8.6.5/bin/ghc -rtsopts -threaded
-clear-package-db -global-package-db -hide-all-packages -package base
-main-is StackSetupShim.mainOverride -package Cabal-2.4.0.1
/Users/admin/.stack/setup-exe-src/setup-6HauvNHV.hs
/Users/admin/.stack/setup-exe-src/setup-shim-6HauvNHV.hs -o
/Users/admin/.stack/setup-exe-cache/x86_64-osx/tmp-Cabal-simple_6HauvNHV_2.4.0.1_ghc-8.6.5
Process exited with code: ExitFailure 1
admin@admins-MacBook-Pro-2 project1 %
I have written quite a number of programs in Haskell, but have never used cabal, stack or package.
I tried the reddit user's suggestion (see above), which resulted in failure (see above). Before that, I had experimented with stack and cabal, but my attempts failed. The cabal and stack User Manuals do not seem to help much.