Skip to content

Instantly share code, notes, and snippets.

@mohaalak
Last active December 29, 2021 06:53
Show Gist options
  • Save mohaalak/f9965e5d3ae3d669d7aa279e1976b74b to your computer and use it in GitHub Desktop.
Save mohaalak/f9965e5d3ae3d669d7aa279e1976b74b to your computer and use it in GitHub Desktop.
player and enemy over abstraction command creation
module Main where
import Prelude
import Data.Symbol (class IsSymbol)
import Prim.Row (class Cons)
import Type.Proxy (Proxy(..))
import Unsafe.Coerce (unsafeCoerce)
type PlayerRow
=
( name :: String
, hp :: Number
, atk :: Number
, speed :: Number
)
type EnemyRow
=
( name :: String
, hp :: Number
, atk :: Number
, speed :: Number
, foo :: Array Number
)
type IndexRow =
( player :: PlayerRow
, enemy :: EnemyRow
)
mkCmd
:: forall indexField (indexType :: Row Type) indexTail field fieldType fieldTail
. IsSymbol field
=> IsSymbol indexField
=> Cons indexField indexType indexTail IndexRow
=> Cons field fieldType fieldTail indexType
=> Proxy indexField
-> Proxy field
-> fieldType
-> Record (indexType)
mkCmd index field value = unsafeCoerce 0
c1 = mkCmd (Proxy :: Proxy "player") (Proxy :: Proxy "name") "player"
c2 = mkCmd (Proxy :: Proxy "enemy") (Proxy :: Proxy "foo") [ 1.0, 2.0, 3.0 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment