Creating Simpler Struct Example #647
sukhmankkahlon
started this conversation in
Ideas
Replies: 1 comment
-
Here is a bare-bones example which defines a single struct, along with a stream that shows how to create values of that struct's type: {-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
module Main (main) where
import GHC.Generics (Generic)
import Copilot.Compile.Bluespec
import Language.Copilot
data Coord = Coord
{ x :: Field "x" Word16
, y :: Field "y" Word16
} deriving Generic
instance Struct Coord where
typeName = typeNameDefault
toValues = toValuesDefault
updateField = updateFieldDefault
instance Typed Coord where
typeOf = typeOfDefault
coords :: Stream Coord
coords = constant (Coord { x = Field 1, y = Field 2 })
spec :: Spec
spec = trigger "coords" true [arg coords]
main :: IO ()
main = do
spec' <- reify spec
compile "Coord" spec' |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The current Co-pilot Example under copilot>copilot>examples includes a Struct.hs example which contains struct Battery with fields volts, temp, other. Would anyone care to create a even simpler struct example that has outputs with dummy values rather than external, that way it could be simulated very easily? It would help in the understanding of the code and how it changes when compiled to blue-spec or C.
Beta Was this translation helpful? Give feedback.
All reactions