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

Adding devShells to play with generated schema code for Haskell's Prelude and Plutus Prelude #122

Merged
merged 3 commits into from
Oct 24, 2023

Conversation

jaredponn
Copy link
Collaborator

@jaredponn jaredponn commented Oct 24, 2023

This PR does the following:

  • Added the following attributes in libs/build.nix
    • dev-prelude-haskell: a devShell for when someone wants to play with libs/lbf-prelude/Prelude.lbf in Haskell
    • dev-plutustx: a devShell for when someone wants to play with libs/lbf-plutus/Plutus/V1.lbf or libs/lbf-plutus/Plutus/V2.lbf in Haskell

The rest of the sections demonstrate how to use.

dev-prelude-haskell

The following demonstrates script output (with some details omitted) of playing around with TEST.lbf with the developer shell for dev-prelude-haskell. Commands are prefixed with $ and output follows.

Note the --ignore-environment flag is just used for demonstration purposes to show that the devShell environment really is complete with the required information.

$ nix develop --ignore-environment .#dev-prelude-haskell
xset:  unable to open display ""
WARNING: pre-commit-hooks.nix: git command not found; skipping installation.
$ cat TEST.lbf
module TEST

import Prelude

sum Dog = Dog Integer

derive Eq Dog

$ lbf-prelude-to-haskell TEST.lbf
mkdir: cannot create directory ‘.work’: File exists
[lbf][INFO] Success from: /nix/store/hn87z4b5qaw1888zys761nyxwm2gyxal-lambda-buffers-compiler-exe-lbc-0.1.0.0/bin/lbc compile --input-file .work/compiler-input.pb --output-file .work/compiler-output.pb
[lbf][INFO] Compilation OK
[lbf][INFO] Success from: /nix/store/9s58v4ad8bk4qq0ml0cirpcgfr1nfaj8-lbg-haskell/bin/lbg-haskell --input .work/codegen-input.pb --output .work/codegen-output.pb --gen-dir autogen --gen-class Prelude.Eq --gen-class Prelude.Json '--config=/nix/store/7h1hnhy5al8v272c4l1vrsxc2h3i9si4-codegen-configs/haskell-prelude-base.json' TEST
[lbf][INFO] Codegen OK
$ cat autogen/LambdaBuffers/TEST.hs
module LambdaBuffers.TEST (Dog(..)) where

import qualified LambdaBuffers.Prelude
import qualified Prelude


data Dog = Dog'Dog LambdaBuffers.Prelude.Integer deriving Prelude.Show


instance Prelude.Eq Dog where
  (==) = (\x0 -> (\x1 -> case x0 of
                           Dog'Dog x2 -> case x1 of
                                           Dog'Dog x3 -> (Prelude.&&) (Prelude.True) ((Prelude.==) (x2) (x3)) ) )
$ ghci autogen/LambdaBuffers/TEST.hs
GHCi, version 9.2.5: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/jared/Documents/Work/lambda-buffers/.ghci
[1 of 1] Compiling LambdaBuffers.TEST ( autogen/LambdaBuffers/TEST.hs, interpreted )
Ok, one module loaded.
 :i Dog
type Dog :: *
data Dog = Dog'Dog LambdaBuffers.Prelude.Integer
  	-- Defined at autogen/LambdaBuffers/TEST.hs:7:1
instance Prelude.Eq Dog
  -- Defined at autogen/LambdaBuffers/TEST.hs:10:10
instance Prelude.Show Dog
  -- Defined at autogen/LambdaBuffers/TEST.hs:7:59
 Dog'Dog 0
Dog'Dog 0

Leaving GHCi.

dev-plutustx

Similarly to the previous section, the following demonstrates script output (with some details omitted) of playing around with TEST.lbf with the developer shell for dev-plutustx. Commands are prefixed with $ and output follows.

Note the --ignore-environment flag is just used for demonstration purposes to show that the devShell environment really is complete with the required information.

$ nix develop --ignore-environment .#dev-plutustx
trace: WARNING: 9.2.5 is out of date, consider using 9.2.7.
xset:  unable to open display ""
WARNING: pre-commit-hooks.nix: git command not found; skipping installation.
$ cat TEST.lbf
module TEST

import Prelude (Eq)
import Plutus.V1
import Plutus.V2

sum Dog = Dog Address TxOut

derive Eq Dog
derive PlutusData Dog
$ lbf-plutus-to-haskell TEST.lbf
mkdir: cannot create directory ‘autogen’: File exists
mkdir: cannot create directory ‘.work’: File exists
[lbf][INFO] Success from: /nix/store/hn87z4b5qaw1888zys761nyxwm2gyxal-lambda-buffers-compiler-exe-lbc-0.1.0.0/bin/lbc compile --input-file .work/compiler-input.pb --output-file .work/compiler-output.pb
[lbf][INFO] Compilation OK
[lbf][INFO] Success from: /nix/store/9s58v4ad8bk4qq0ml0cirpcgfr1nfaj8-lbg-haskell/bin/lbg-haskell --input .work/codegen-input.pb --output .work/codegen-output.pb --gen-dir autogen --gen-class Prelude.Eq --gen-class Prelude.Json --gen-class Plutus.V1.PlutusData '--config=/nix/store/7h1hnhy5al8v272c4l1vrsxc2h3i9si4-codegen-configs/haskell-prelude-base.json' '--config=/nix/store/7h1hnhy5al8v272c4l1vrsxc2h3i9si4-codegen-configs/haskell-plutus-plutustx.json' TEST
[lbf][INFO] Codegen OK
$ cat autogen/LambdaBuffers/TEST.hs
module LambdaBuffers.TEST (Dog(..)) where

import qualified LambdaBuffers.Plutus.V1
import qualified LambdaBuffers.Plutus.V2
import qualified LambdaBuffers.Prelude
import qualified LambdaBuffers.Runtime.Plutus
import qualified PlutusTx
import qualified PlutusTx.Builtins
import qualified PlutusTx.Eq
import qualified Prelude


data Dog = Dog'Dog LambdaBuffers.Plutus.V1.Address
                   LambdaBuffers.Plutus.V2.TxOut deriving Prelude.Show


instance Prelude.Eq Dog where
  (==) = (\x0 -> (\x1 -> case x0 of
                           Dog'Dog x2 x3 -> case x1 of
                                              Dog'Dog x4 x5 -> (Prelude.&&) ((Prelude.&&) (Prelude.True) ((Prelude.==) (x2) (x4))) ((Prelude.==) (x3) (x5)) ) )

instance PlutusTx.Eq.Eq Dog where
  (==) = (\x0 -> (\x1 -> case x0 of
                           Dog'Dog x2 x3 -> case x1 of
                                              Dog'Dog x4 x5 -> (Prelude.&&) ((Prelude.&&) (Prelude.True) ((PlutusTx.Eq.==) (x2) (x4))) ((PlutusTx.Eq.==) (x3) (x5)) ) )

instance PlutusTx.ToData Dog where
  toBuiltinData = (\x0 -> case x0 of
                            Dog'Dog x1 x2 -> PlutusTx.Builtins.mkConstr (0) ([PlutusTx.toBuiltinData (x1)
                                                                              , PlutusTx.toBuiltinData (x2)]) )

instance PlutusTx.FromData Dog where
  fromBuiltinData = (\x0 -> LambdaBuffers.Runtime.Plutus.casePlutusData ((\x1 -> (\x2 -> case x1 of
                                                                                           0 -> case x2 of
                                                                                                  [x3
                                                                                                   , x4] -> (Prelude.>>=) (PlutusTx.fromBuiltinData (x3)) ((\x5 -> (Prelude.>>=) (PlutusTx.fromBuiltinData (x4)) ((\x6 -> Prelude.Just (Dog'Dog x5 x6) )) ))
                                                                                                  x7 -> Prelude.Nothing
                                                                                           x8 -> Prelude.Nothing ) )) ((\x9 -> Prelude.Nothing )) ((\x10 -> case x10 of
                                                                                                                                                              x11 -> Prelude.Nothing )) ((\x12 -> Prelude.Nothing )) (x0) )
$ ghci autogen/LambdaBuffers/TEST.hs
GHCi, version 9.2.5: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/jared/Documents/Work/lambda-buffers/.ghci
[1 of 1] Compiling LambdaBuffers.TEST ( autogen/LambdaBuffers/TEST.hs, interpreted )
Ok, one module loaded.
 :i Dog
type Dog :: *
data Dog
  = Dog'Dog LambdaBuffers.Plutus.V1.Address
            LambdaBuffers.Plutus.V2.TxOut
  	-- Defined at autogen/LambdaBuffers/TEST.hs:13:1
instance PlutusTx.Eq.Eq Dog
  -- Defined at autogen/LambdaBuffers/TEST.hs:22:10
instance Prelude.Eq Dog
  -- Defined at autogen/LambdaBuffers/TEST.hs:17:10
instance PlutusTx.FromData Dog
  -- Defined at autogen/LambdaBuffers/TEST.hs:32:10
instance Prelude.Show Dog
  -- Defined at autogen/LambdaBuffers/TEST.hs:14:59
instance PlutusTx.ToData Dog
  -- Defined at autogen/LambdaBuffers/TEST.hs:27:10
 :t Dog'Dog
Dog'Dog
  :: LambdaBuffers.Plutus.V1.Address
     -> LambdaBuffers.Plutus.V2.TxOut -> Dog
 :i LambdaBuffers.Plutus.V1.Address
type LambdaBuffers.Plutus.V1.Address :: *
type LambdaBuffers.Plutus.V1.Address =
  PlutusLedgerApi.V1.Address.Address
  	-- Defined in ‘LambdaBuffers.Plutus.V1’
 import PlutusLedgerApi.V1
PlutusLedgerApi.V1                    PlutusLedgerApi.V1.Crypto             PlutusLedgerApi.V1.Scripts
PlutusLedgerApi.V1.Address            PlutusLedgerApi.V1.DCert              PlutusLedgerApi.V1.Time
PlutusLedgerApi.V1.Bytes              PlutusLedgerApi.V1.EvaluationContext  PlutusLedgerApi.V1.Tx
PlutusLedgerApi.V1.Contexts           PlutusLedgerApi.V1.Interval           PlutusLedgerApi.V1.Value
PlutusLedgerApi.V1.Credential         PlutusLedgerApi.V1.ParamName
 import PlutusLedgerApi.V1
 :i Address
type Address :: *
data Address
  = Address {addressCredential :: Credential,
             addressStakingCredential :: Prelude.Maybe StakingCredential}
  	-- Defined in ‘PlutusLedgerApi.V1.Address’
instance Prelude.Eq Address
  -- Defined in ‘PlutusLedgerApi.V1.Address’
instance Prelude.Ord Address
  -- Defined in ‘PlutusLedgerApi.V1.Address’
instance Prelude.Show Address
  -- Defined in ‘PlutusLedgerApi.V1.Address’
instance PlutusTx.Eq.Eq Address
  -- Defined in ‘PlutusLedgerApi.V1.Address’
instance FromData Address
  -- Defined in ‘PlutusLedgerApi.V1.Address’
instance ToData Address -- Defined in ‘PlutusLedgerApi.V1.Address’
instance UnsafeFromData Address
  -- Defined in ‘PlutusLedgerApi.V1.Address’

Leaving GHCi.

@jaredponn jaredponn force-pushed the jared/114-leftovers-haskell-dev-shell branch from 3759b03 to 6315ffa Compare October 24, 2023 06:05
@jaredponn jaredponn linked an issue Oct 24, 2023 that may be closed by this pull request
6 tasks
@jaredponn jaredponn force-pushed the jared/114-leftovers-haskell-dev-shell branch 2 times, most recently from 2e52d5a to d60528d Compare October 24, 2023 07:17
Copy link
Collaborator

@bladyjoker bladyjoker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hoping for your comments!

libs/build.nix Outdated Show resolved Hide resolved
libs/build.nix Show resolved Hide resolved
libs/build.nix Show resolved Hide resolved
libs/build.nix Outdated Show resolved Hide resolved
@jaredponn
Copy link
Collaborator Author

Rebasing and merging now.

@jaredponn jaredponn force-pushed the jared/114-leftovers-haskell-dev-shell branch from 9157ed1 to 5cd920c Compare October 24, 2023 22:27
@jaredponn jaredponn mentioned this pull request Oct 24, 2023
6 tasks
@jaredponn jaredponn added this pull request to the merge queue Oct 24, 2023
Merged via the queue into main with commit 9b3132b Oct 24, 2023
2 checks passed
@jaredponn jaredponn deleted the jared/114-leftovers-haskell-dev-shell branch October 24, 2023 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Leftovers #114
2 participants