2

In Clash official website, there is the following example :

>>> sampleN @System 4 (register 0 (pure (8 :: Signed 8)))

I know what is a pure function, but why this keyword here ? If I remove it I got an error :

Clash.Prelude> sampleN @System 4 (register 0 (8 :: Signed 8))

<interactive>:2:32: error:
    * Couldn't match expected type `Signal System a'
                  with actual type `Signed 8'
    * In the second argument of `register', namely `(8 :: Signed 8)'
      In the third argument of `sampleN', namely
        `(register 0 (8 :: Signed 8))'
      In the expression: sampleN @System 4 (register 0 (8 :: Signed 8))
    * Relevant bindings include it :: [a] (bound at <interactive>:2:1)

Any clue ?

FabienM
  • 3,421
  • 23
  • 45
  • 6
    [`pure`](https://hackage.haskell.org/package/base-4.12.0.0/docs/Prelude.html#v:pure) is not a keyword, it is just another function, taking a `Signed 8` and returning a value of type `Signal System a`. – Micha Wiedenmann Oct 16 '19 at 07:00

1 Answers1

5

Signal has an instance of Applicative to which pure belongs. pure :: a -> Signal dom a lifts a value of type Signed 8 to Signal dom (Signed 8). Which unifies with Signal System a in that context to result in Signal System (Signed 8).

Reference used: http://hackage.haskell.org/package/clash-prelude-1.0.0/docs/Clash-Signal.html

Dan D.
  • 73,243
  • 15
  • 104
  • 123