PureScript

1 program Added 2025-10-22T09:58:18Z Model: anthropic/claude-3.5-sonnetTemp: 0.4 Evidence Report issue View issues
Aliases: purs
Provenance: commit a0690a4fba · authored 2025-10-22T11:58:18+02:00 · model anthropic/claude-3.5-sonnet

Sources mentioning this language

6 sources · pl_id: pl/purescript
LLM (this repo) · 1PldbLinguistWikipediaHyperpolyglotWikidata · Q65082796

Wikipedia infobox

Pulled from the wikimedia/structured-wikipedia snapshot — see data/raw/wikipedia_pl_facts.*.jsonl and pl_fact.csv for the long-table provenance.

Paradigmsfunctional
Typinginferred, static, strong
Designed byPhil Freeman
First appeared2013
Influenced byHaskell · JavaScript
LicenseBSD 3-clause
Homepagehttps://www.purescript.org/

Extensions claimed by this language

2 claims. Each row is one upstream assertion with its strength. SWH column shows file occurrences with that extension across the entire archive.
ExtensionSourceStrengthSWH
.purslinguistprimary505.1K files
.purswikipediaproposed505.1K files

Related languages

Purerl (0.41)ReScript (0.39)PuzzleScript (0.38)PostScript (0.36)ClojureScript (0.36)

LLM-contributed programs

Simple Counter Component

Provenance: commit a0690a4fba · authored 2025-10-22T11:58:18+02:00 · model anthropic/claude-3.5-sonnet · Temp 0.4
code.purs · license: BSD-3-Clause · added: 2025-10-22T09:58:18Z
module Main where

import Prelude
import Effect (Effect)
import Halogen as H
import Halogen.Aff as HA
import Halogen.HTML as HH
import Halogen.HTML.Events as HE
import Halogen.VDom.Driver (runUI)

main :: Effect Unit
main = HA.runHalogenAff do
  body <- HA.awaitBody
  runUI component unit body

type State = { count :: Int }

data Action = Increment | Decrement

component :: forall q i o m. H.Component q i o m
component =
  H.mkComponent
    { initialState
    , render
    , eval: H.mkEval $ H.defaultEval { handleAction = handleAction }
    }

initialState :: forall i. i -> State
initialState _ = { count: 0 }

render :: forall m. State -> H.ComponentHTML Action () m
render state =
  HH.div_
    [ HH.button [ HE.onClick \_ -> Decrement ] [ HH.text "-" ]
    , HH.text (show state.count)
    , HH.button [ HE.onClick \_ -> Increment ] [ HH.text "+" ]
    ]

handleAction :: forall o m. Action -> H.HalogenM State Action () o m Unit
handleAction = case _ of
  Increment -> H.modify_ \st -> st { count = st.count + 1 }
  Decrement -> H.modify_ \st -> st { count = st.count - 1 }

Real programs from Software Heritage

1 sample mined from derived_datasets/<date>/contents/*.parquet, byte-verified against the SWH archive. Citation-grade qualified SWHIDs preserved.
TreasuryTrip.purs · 9346 B · ext .purs · seen 6× in SWH
via unique-primary
swh:1:cnt:33a2e4ab6c6a9a7ea6acdd78a80add59e31ad1d6;origin=https://github.com/yaadlabs/DAO-Off-Chain;anchor=swh:1:rev:4ed2f20c0a3766076abade1a9bd73d26c39f3632;path=/src/Dao/Workflow/TreasuryTrip.purs
Open in SWH · Raw bytes (SWH) · GitHub raw
Show source
{-|
Module: Dao.Workflow.TreasuryTrip
Description: Contract for disbursing treasury funds based on a trip proposal
-}
module Dao.Workflow.TreasuryTrip (treasuryTrip) where

import Contract.Address (Address, PaymentPubKeyHash)
import Contract.Log (logInfo')
import Contract.Monad (Contract, liftContractM)
import Contract.PlutusData (unitDatum)
import Contract.Prelude
  ( bind
  , discard
  , mconcat
  , min
  , pure
  , unwrap
  , (#)
  , ($)
  , (*)
  , (+)
  , (-)
  , (/)
  , (>=)
  )
import Contract.ScriptLookups as Lookups
import Contract.Scripts (Validator, ValidatorHash, validatorHash)
import Contract.Transaction
  ( TransactionHash
  , submitTxFromConstraints
  )
import Contract.TxConstraints as Constraints
import Contract.Value
  ( CurrencySymbol
  , TokenName
  , Value
  , adaSymbol
  , adaToken
  , singleton
  )
import Dao.Component.Config.Params (mkValidatorConfig)
import Dao.Component.Config.Query (ConfigInfo, referenceConfigUtxo)
import Dao.Component.Tally.Query (TallyInfo, referenceTallyUtxo)
import Dao.Component.Treasury.Params (TreasuryParams)
import Dao.Component.Treasury.Query (TreasuryInfo, spendTreasuryUtxo)
import Dao.Scripts.Validator
  ( unappliedConfigValidator
  , unappliedTallyValidator
  , unappliedTreasuryValidator
  )
import Dao.Utils.Address (addressToPaymentPubKeyHash)
import Dao.Utils.Error (guardContract)
import Dao.Utils.Value (allPositive, normaliseValue, valueSubtraction)
import Data.Maybe (Maybe(Just, Nothing))
import JS.BigInt (BigInt, fromInt)
import LambdaBuffers.ApplicationTypes.Configuration (DynamicConfigDatum)
import LambdaBuffers.ApplicationTypes.Proposal (ProposalType(ProposalType'Trip))
import LambdaBuffers.ApplicationTypes.Tally (TallyStateDatum)

-- | Contract for disbursing treasury funds based on a trip proposal
treasuryTrip :: TreasuryParams -> Contract TransactionHash
treasuryTrip params' = do
  logInfo' "Entering treasuryTrip transaction"

  let params = params' # unwrap

  -- Make the scripts
  let
    validatorConfig = mkValidatorConfig params.configSymbol
      params.configTokenName
  appliedTreasuryValidator :: Validator <- unappliedTreasuryValidator
    validatorConfig
  appliedTallyValidator :: Validator <- unappliedTallyValidator
    validatorConfig
  appliedConfigValidator :: Validator <- unappliedConfigValidator
    validatorConfig

  -- Query the UTXOs
  configInfo :: ConfigInfo <- referenceConfigUtxo params.configSymbol
    appliedConfigValidator
  tallyInfo :: TallyInfo <- referenceTallyUtxo params.tallySymbol
    params.proposalTokenName
    appliedTallyValidator
  treasuryInfo :: TreasuryInfo <-
    spendTreasuryUtxo
      params.treasurySymbol
      appliedTreasuryValidator

  let
    -- The main config referenced at the config UTXO
    dynamicConfig :: DynamicConfigDatum
    dynamicConfig = configInfo.datum

    -- Get the treasury payment info from the 'TallyStateDatum'
    tallyDatum :: TallyStateDatum
    tallyDatum = tallyInfo.datum

  -- Get the treasury payment info from the 'TallyStateDatum'
  travelAgentAddress :: Address <- liftContractM "Not a trip proposal" $
    getTravelAgentAddress tallyDatum
  travellerAddress :: Address <- liftContractM "Not a trip proposal" $
    getTravellerAddress tallyDatum
  totalTravelCost :: BigInt <- liftContractM "Not a trip proposal" $
    getTravelCost tallyDatum

  travelAgentPaymentKey :: PaymentPubKeyHash <-
    liftContractM "Could not convert address to key" $
      addressToPaymentPubKeyHash travelAgentAddress
  travellerPaymentKey :: PaymentPubKeyHash <-
    liftContractM "Could not convert address to key" $
      addressToPaymentPubKeyHash travellerAddress

  let
    -- The number of votes cast in favour of the proposal
    votesFor :: BigInt
    votesFor = tallyDatum # unwrap # _.for

    -- The number of votes cast in opposition to the proposal
    votesAgainst :: BigInt
    votesAgainst = tallyDatum # unwrap # _.against

    totalVotes :: BigInt
    totalVotes = votesFor + votesAgainst

    -- Set in 'createConfig' tx, must not be zero
    configTotalVotes :: BigInt
    configTotalVotes = dynamicConfig # unwrap # _.totalVotes

    -- Calculates the 'relative majority' based on on-chain script requirements
    -- This value must exceed 'configTripRelativeMajorityPercent' threshold
    -- set in the 'DynamicConfigDatum'
    relativeMajority :: BigInt
    relativeMajority = (totalVotes * (fromInt 1000)) / configTotalVotes

    -- Calculates the 'majority' based on on-chain script requirements
    -- This value must exceed 'configTripMajorityPercent' threshold
    -- set in the 'DynamicConfigDatum'
    majorityPercent :: BigInt
    majorityPercent = (votesFor * (fromInt 1000)) / totalVotes

    -- Get the 'configTripRelativeMajorityPercent' threshold from the config
    configTripRelativeMajorityPercent :: BigInt
    configTripRelativeMajorityPercent = dynamicConfig # unwrap #
      _.tripRelativeMajorityPercent

    -- Get the 'configTripRelativeMajorityPercent' threshold from the config
    configTripMajorityPercent :: BigInt
    configTripMajorityPercent = dynamicConfig # unwrap # _.tripMajorityPercent

    -- A max threshold for the disbursement amount
    configMaxTripDisbursement :: BigInt
    configMaxTripDisbursement = dynamicConfig # unwrap # _.maxTripDisbursement

    -- Get the amount to send to the travel agent's address
    configAgentDisbursementPercent :: BigInt
    configAgentDisbursementPercent = dynamicConfig # unwrap #
      _.agentDisbursementPercent

    -- Get the total cost, which cannot exceed the max threshold specified
    disbursementAmount :: BigInt
    disbursementAmount = min configMaxTripDisbursement totalTravelCost

    disbursementAmountLovelaces :: Value
    disbursementAmountLovelaces = singleton adaSymbol adaToken
      disbursementAmount

    -- The value held at the treasury input UTXO which
    -- must cover the disbursement amount
    treasuryInputAmount :: Value
    treasuryInputAmount = treasuryInfo.value

    -- The change to send back to the treasury
    amountToSendBackToTreasuryLovelaces :: Value
    amountToSendBackToTreasuryLovelaces = normaliseValue
      (valueSubtraction treasuryInputAmount disbursementAmountLovelaces)

    -- Caluclate amount to send to the travel agent
    amountToSendToTravelAgent :: BigInt
    amountToSendToTravelAgent =
      (totalTravelCost * configAgentDisbursementPercent) / (fromInt 1000)

    -- Caluclate the amount to send to the traveller
    amountToSendToTraveller :: BigInt
    amountToSendToTraveller = totalTravelCost - amountToSendToTravelAgent

    amountToSendToTravelAgentLovelaces :: Value
    amountToSendToTravelAgentLovelaces = singleton adaSymbol adaToken
      amountToSendToTravelAgent

    amountToSendToTravellerLovelaces :: Value
    amountToSendToTravellerLovelaces = singleton adaSymbol adaToken
      amountToSendToTraveller

  -- Check that the treasury input amount covers the payment amount
  guardContract "Not enough treasury funds to cover payment" $ allPositive
    amountToSendBackToTreasuryLovelaces

  -- Check for sufficient votes
  guardContract "Relative majority is too low" $ relativeMajority >=
    configTripRelativeMajorityPercent
  guardContract "Majority percent is too low" $ majorityPercent >=
    configTripMajorityPercent

  let
    treasuryValidatorHash :: ValidatorHash
    treasuryValidatorHash = validatorHash appliedTreasuryValidator

    lookups :: Lookups.ScriptLookups
    lookups =
      mconcat
        [ configInfo.lookups
        , tallyInfo.lookups
        , treasuryInfo.lookups
        ]

    constraints :: Constraints.TxConstraints
    constraints =
      mconcat
        [ Constraints.mustPayToScript
            treasuryValidatorHash
            unitDatum
            Constraints.DatumInline
            amountToSendBackToTreasuryLovelaces
        -- ^ Pay the change back to the treasury
        , Constraints.mustPayToPubKey
            travellerPaymentKey
            amountToSendToTravellerLovelaces
        -- Pay the traveller their share
        , Constraints.mustPayToPubKey
            travelAgentPaymentKey
            amountToSendToTravelAgentLovelaces
        -- Pay the travel agent their share
        , treasuryInfo.constraints
        , configInfo.constraints
        , tallyInfo.constraints
        ]

  txHash <- submitTxFromConstraints lookups constraints

  pure txHash
  where
  -- Get the travel agent's address from the tally datum
  getTravelAgentAddress :: TallyStateDatum -> Maybe Address
  getTravelAgentAddress tallyDatum =
    let
      proposalType = tallyDatum # unwrap # _.proposal
    in
      case proposalType of
        (ProposalType'Trip address _ _) -> Just address
        _ -> Nothing

  -- Get the traveller's address from the tally datum
  getTravellerAddress :: TallyStateDatum -> Maybe Address
  getTravellerAddress tallyDatum =
    let
      proposalType = tallyDatum # unwrap # _.proposal
    in
      case proposalType of
        (ProposalType'Trip _ address _) -> Just address
        _ -> Nothing

  -- Get the total cost of the disbursement from the tally datum
  getTravelCost :: TallyStateDatum -> Maybe BigInt
  getTravelCost tallyDatum =
    let
      proposalType = tallyDatum # unwrap # _.proposal
    in
      case proposalType of
        (ProposalType'Trip _ _ amount) -> Just amount
        _ -> Nothing

Contribute — propose a file extension

Tell us where to find evidence about PureScript (mapped to pl/purescript). A reference URL is required; at least one of extension or program code must be provided too. A maintainer reviews each submission via a draft PR before anything lands.
Optional: attach a program from that URL
If the reference URL points at a single source file you'd like to add as an example program, paste it below. The workflow will write it under languages/PureScript/programs/<sha>/. Keep under ~200 lines.
(or open the pre-filled issue directly)
← Purerl PureStack →