Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example in tutorial broken? #324

Closed
tommythorn opened this issue Jun 26, 2018 · 2 comments
Closed

Example in tutorial broken? #324

tommythorn opened this issue Jun 26, 2018 · 2 comments
Labels

Comments

@tommythorn
Copy link

tommythorn commented Jun 26, 2018

EDIT: Thanks for a making this. It looks really great.

I was trying to follow the examples in the tutorial, but it seems to not work:

$ cat MAC.hs
module MAC where

import Clash.Prelude
import Clash.Explicit.Testbench

ma acc (x,y) = acc + x * y

macT acc (x,y) = (acc',o)
  where
    acc' = ma acc (x,y)
    o    = acc

mac = mealy macT 0

topEntity
  :: Clock System Source
  -> Reset System Asynchronous
  -> Signal System (Signed 9, Signed 9)
  -> Signal System (Signed 9)
topEntity = exposeClockReset mac
{-# NOINLINE topEntity #-}

testBench :: Signal System Bool
testBench = done
  where
    testInput    = stimuliGenerator clk rst $ (listToVecTH [(1,1) :: (Signed 9,Signed 9),(2,2),(3,3),(4,4)])
    expectOutput = outputVerifier clk rst $(listToVecTH [0 :: Signed 9,1,5,14])
    done         = expectOutput (topEntity clk rst testInput)
    clk          = tbSystemClockGen (not <$> done)
    rst          = systemResetGen

$ clashi MAC.hs 
CLaSHi, version 0.99 (using clash-lib, version 0.99):
http://www.clash-lang.org/  :? for help
[1 of 1] Compiling MAC              ( MAC.hs, interpreted )

MAC.hs:26:48: error:
    • Couldn't match type ‘Language.Haskell.TH.Syntax.Q
                             Language.Haskell.TH.Syntax.Exp’
                     with ‘Vec l0 (Signed 9, Signed 9)’
      Expected type: Vec l0 (Signed 9, Signed 9)
        Actual type: Language.Haskell.TH.Lib.Internal.ExpQ
    • In the second argument of ‘($)’, namely
        ‘(listToVecTH
            [(1, 1) :: (Signed 9, Signed 9), (2, 2), (3, 3), (4, 4)])’
      In the expression:
        stimuliGenerator clk rst
          $ (listToVecTH
               [(1, 1) :: (Signed 9, Signed 9), (2, 2), (3, 3), (4, 4)])
      In an equation for ‘testInput’:
          testInput
            = stimuliGenerator clk rst
                $ (listToVecTH
                     [(1, 1) :: (Signed 9, Signed 9), (2, 2), (3, 3), ....])
   |
26 |     testInput    = stimuliGenerator clk rst $ (listToVecTH [(1,1) :: (Signed 9,Signed 9),(2,2),(3,3),(4,4)])
   |                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
@christiaanb
Copy link
Member

In the line:

testInput    = stimuliGenerator clk rst $ (listToVecTH [(1,1) :: (Signed 9,Signed 9),(2,2),(3,3),(4,4)])

there is a space between $ and ( which is causing the error. The issue is that $( ... ) is a special type of bracket which inserts a compile-time generated AST into the code, which is called Template Haskell: https://downloads.haskell.org/~ghc/8.4.3/docs/html/users_guide/glasgow_exts.html#template-haskell

To fix, change the line to:

testInput    = stimuliGenerator clk rst $(listToVecTH [(1,1) :: (Signed 9,Signed 9),(2,2),(3,3),(4,4)])

Did you get this error from copy/pasting the code? If so, which OS are you using? because on my Linux machine copy/pasting the code from: http://hackage.haskell.org/package/clash-prelude-0.99.1/docs/Clash-Tutorial.html#g:7 doesn't result in a space between $ and (

@tommythorn
Copy link
Author

oops. I reformatted the line and when it didn't work reverted my change, incompletely it would seem. Sorry and thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants