Skip to content

Commit

Permalink
add hashing.hs
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Jul 23, 2019
1 parent 5a67143 commit a24c87c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
21 changes: 21 additions & 0 deletions hashing.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}

import Data.Hashable (Hashable (hash))
import Data.Word (Word8)
import GHC.Generics (Generic)

data Color =
Color
{ red :: Word8
, green :: Word8
, blue :: Word8
}
deriving stock (Show, Generic)
deriving anyclass (Hashable)

main =
do
putStrLn (show (hash (Color 255 0 0)))
putStrLn (show (hash (Color 0 255 0)))
2 changes: 2 additions & 0 deletions outputs/hashing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
7246417153327675019
7199408575939581793
7 changes: 2 additions & 5 deletions tools/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ rec {

inherit (pkgs) callPackage haskellPackages;

ghc = haskellPackages.ghcWithPackages (p: [
p.bytestring
p.text
]);
haskell = callPackage ./haskell.nix {};

inherit (haskellPackages) ghcid;

outputs = callPackage ./outputs.nix { inherit ghc; };
outputs = callPackage ./outputs.nix { inherit haskell; };

}
7 changes: 7 additions & 0 deletions tools/haskell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ haskellPackages }:

haskellPackages.ghcWithPackages (p: [
p.bytestring
p.hashable
p.text
])
5 changes: 3 additions & 2 deletions tools/outputs.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{ runCommand, linkFarm, ghc }:
{ runCommand, linkFarm, haskell }:

let
run = name: hsFile:
{
inherit name;
path = runCommand "phrasebook-output-${name}.txt"
{
buildInputs = [ ghc ];
buildInputs = [ haskell ];
inherit hsFile;
}
''
Expand All @@ -20,4 +20,5 @@ in
(run "hello-world.txt" ../hello-world.hs)
(run "common-types.txt" ../common-types.hs)
(run "variables.txt" ../variables.hs)
(run "hashing.txt" ../hashing.hs)
]

0 comments on commit a24c87c

Please sign in to comment.