Last active
December 29, 2021 06:53
-
-
Save mohaalak/f9965e5d3ae3d669d7aa279e1976b74b to your computer and use it in GitHub Desktop.
player and enemy over abstraction command creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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