clash-lang / clash-prelude

CLaSH prelude library containing datatypes and functions for circuit design
http://www.clash-lang.org/
Other
31 stars 27 forks source link

unsafeSNat doesn't synthesise #141

Open cchalmers opened 6 years ago

cchalmers commented 6 years ago
import Clash.Prelude
import Clash.Promoted.Nat.Unsafe

topEntity :: SystemClockReset => Signal System Bool
topEntity = metronome 4

metronome :: SystemClockReset => Integer -> Signal System Bool
metronome i =
  case unsafeSNat i of
    n@SNat -> (==0) <$> counter n

counter :: SystemClockReset => SNat i -> Signal System (Index i)
counter SNat = go where
  go = register 0 $ fmap (\i -> if i == maxBound then 0 else i+1) go

errors with

<no location info>: error:
    Clash error call:
    Clash.Netlist.BlackBox(116): Forced to evaluate untranslatable type: (Clash.Sized.Internal.Index.fromInteger#
  @(GHC.Types.Any GHC.Types.Nat)
  \$dKnownNat\
  0 :: Clash.Sized.Internal.Index.Index (GHC.Types.Any GHC.Types.Nat))
christiaanb commented 6 years ago

I think we'll have to wait for -XDependentTypes in GHC in order to support this.