This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- mostly ripped off from https://teh.id.au/posts/2017/02/13/interactive-print/index.html | |
:{ | |
:def pp (\_ -> return | |
$ unlines ["import qualified Text.Show.Pretty as SP", | |
"import qualified Language.Haskell.HsColour as HSC", | |
"import Language.Haskell.HsColour.Colourise (defaultColourPrefs)", | |
"_colorPrint = putStrLn . HSC.hscolour HSC.TTY defaultColourPrefs False False \"\" False . SP.ppShow", | |
":set -interactive-print _colorPrint"]) | |
:} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo a where | |
bar :: a -> String | |
instance {-# OVERLAPPING #-} Foo String where | |
bar = id | |
instance (Num a, Show a) => Foo a where | |
bar = show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Val = Val { foobar :: Int } deriving (Generic, Show) | |
instance JSON.FromJSON Val where | |
parseJSON = JSON.genericParseJSON | |
$ JSON.defaultOptions { JSON.fieldLabelModifier = filter (/= '-') } | |
{- | |
$ eitherDecode "{\"foo-bar\": 1}" :: Either String Val | |
Left "Error in $: key \"foobar\" not present" | |
-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Validity = Invalid | Valid deriving (Eq, Show, Generic, NFData) | |
data Readiness = NotReady | Ready deriving (Eq, Show, Generic, NFData) | |
asValid x = if x then Valid else Invalid | |
asReady x = if x then Ready else NotReady | |
data DFIO a = DFIO { valid :: Validity, ready :: Readiness, val :: a } deriving (Eq, Show, Generic, NFData) | |
dfio iV oR dat = DFIO (asValid iV) (asReady oR) dat | |
pending placeholder = DFIO Invalid NotReady placeholder | |
done result = DFIO Valid Ready result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- While building custom Setup.hs for package clash-prelude-0.99 using: | |
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_2.0.0.2_ghc-8.2.1.exe --builddir=.stack-work\dist\e53504d9 build lib:clash-prelude --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always" | |
Process exited with code: ExitFailure 1 | |
Logs have been written to: D:\code\clash-compiler\.stack-work\logs\clash-prelude-0.99.log | |
Configuring clash-prelude-0.99... | |
Warning: | |
This package indirectly depends on multiple versions of the same package. This is very likely to cause a compile failure. | |
package time (time-1.8.0.2-6D7zA6hvj7J2L4fRhEphEi) requires Win32-2.4.0.0-6h2GtvaqnjAGgAinwN44RU | |
package time (time-1.8.0.2) requires Win32-2.5.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cabal.exe: Error parsing project file | |
D:\code\clash-compiler\cabal.project:6: | |
Parse of field 'allow-newer' failed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Core.Shift where | |
import CLaSH.Prelude | |
import CLaSH.Signal | |
import CLaSH.Sized.BitVector | |
import Data.Word | |
import Data.Bits | |
type Word256 = BitVector 256 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- tweaking `CLaSH.Sized.Vector.vfold` so that an initial vector can be provided/built upon | |
-- reusing the `Append` motive from the main `dfold` example | |
data Append (m :: Nat) (a :: *) (f :: TyFun Nat *) :: * | |
type instance Apply (Append m a) l = Vec (l + m) a | |
vifold :: forall k j a b . (KnownNat k, KnownNat j) | |
=> (forall l . SNat l -> a -> Vec (j + l) b -> Vec (j + l + 1) b) | |
-> Vec j b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- in `cabal exec clash -- --interactive` | |
CLaSH.Prelude> import Data.Int | |
CLaSH.Prelude Data.Int> let x = 56 :: Int8 | |
CLaSH.Prelude Data.Int> x + x | |
112 | |
-- in `Foo.hs`: | |
module Foo where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def words (set (.split (slurp "g:/words") "\n"))) | |
=> #'user/words | |
(count words) | |
=> 99171 | |
(require '[clojure.math.combinatorics :refer (permutations)]) | |
=> nil | |
(count (permutations "plates")) | |
=> 720 | |
(first (permutations "plates")) | |
=> (\p \l \a \t \e \s) |