Skip to content

Instantly share code, notes, and snippets.

@siers
Last active October 11, 2023 08:05
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save siers/f7772a800a34d7d267a529a150742d0a to your computer and use it in GitHub Desktop.
printing out a lamb
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
};
outputs = { self, nixpkgs }:
with nixpkgs.legacyPackages.x86_64-linux;
let
system = "x86_64-linux";
lamb = writeText "lamb.hs" ''
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImportQualifiedPost #-}
module Main where
import Data.Array.Comfort.Boxed qualified as B
import Data.Array.Comfort.Shape
import Data.Array.Comfort.Storable (Array, fromList)
import Data.Array.Comfort.Storable qualified as S
import Data.Bifunctor
import Data.Bits
import Data.Complex
import Numeric.FFTW.Rank2
import Numeric.FFTW.Shape (Half (..))
print2d :: Array (Cyclic Int, Cyclic Int) Double -> String
print2d a =
foldMap ((++ "\n") . foldMap (\x -> if x > 2 then "o" else " ")) (fmap S.toList . B.toList . S.toRowArray $ a)
numbers = ([3,-80,-38,2,-6,4,8,3,-10,2,3,2,3,-2,-2,-4,3,-2,5,-2,-2,-2,3,-2,7,-2,3,-2,-2,-2,11,-2,-2,7,-2,-2,-2,5,-2,3,-2,-88,-16,3,20,8,3,-6,-4,-8,8,-2,3,-4,-2,-2,5,2,-2,3,-2,9,-2,-2,5,-2,-2,5,-2,3,-2,-2,3,-2,5,-2,-2,-2,7,-2,-2,3,-2,-8,2,99,-18,8,99,-8,8,99,2,4,99,2,101,6,-8,99,2,-2,99,-2,4,101,-4,101,-2,99,-4,101,2,-2,101,-2,99,-4,103,-2,201,-2,307,-2,101,-2,99,-2,103,-2,101,-2,201,-2,-2,203,-2,101,-2,101,-2,99,-2,103,-4,201,-4,2,201,2,101,-4,103,-2,201,-2,101,2,-4,99,6,-4,99,2,-2,99,2,-6,99,-8,8,99,-18,-8,99,-8,-6,99,-88,84,99],[3,-18,32,-22,5,2,-4,2,-4,-2,7,-2,-2,-2,-2,3,-2,3,-2,9,-2,-2,-2,3,-2,-2,5,-2,11,-2,9,-2,-2,5,-2,3,-2,-32,8,2,6,-4,8,-2,-6,-2,-2,4,-4,-2,-2,9,2,-2,3,-2,3,-2,-2,3,-2,-2,3,-2,3,-2,9,-2,-2,3,-2,7,-2,-2,5,-2,3,-2,-6,30,99,-4,101,8,-2,99,-14,8,99,-2,6,99,10,-12,99,2,-2,99,-2,-4,101,-4,201,-4,-2,99,-2,2,99,-4,101,2,-2,99,-2,101,-2,103,-2,101,-2,99,-2,-2,101,-2,201,-2,103,-2,201,-2,-2,101,-2,99,-2,101,-2,203,-2,101,-2,-2,101,-2,201,-4,-2,99,2,203,2,-2,99,-2,101,-2,2,101,-8,99,-4,-4,99,-12,2,101,-2,99,12,-2,99,-10,8,99,2,-4,99,4,20,101,-8,99])
convert =
fromList (Cyclic 50, Half 100)
. map (uncurry (:+) . bimap fromIntegral fromIntegral)
. uncurry zip
. bimap rleD rleD
where
rleD = (>>= \x -> if x .&. 1 == 1 then replicate (div (x - 1) 2) 0 else [div x 2])
main = putStrLn . print2d . S.map (subtract 10.0) . fourierCR . convert $ numbers
'';
ghc = haskellPackages.ghcWithPackages (pkgs: with pkgs; [ base comfort-array comfort-fftw ]);
in
{
packages.${system}.default =
runCommand "lamb" {} ''
mkdir $out
${ghc}/bin/runhaskell ${lamb} > $out/lamb.txt
'';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment