user1679: I need someone to explain to me line by line. The code is from plutu tutorials. https://docs.cardano.org/projects/plutus/en/latest/plutus/tutorials/basic-validators.html
All the code in that page I can understand. Except the last one. I don't really get it. the code that I don't understand:
dateInstance :: ScriptInstance DateValidator
dateInstance = validator @DateValidator
    -- The first argument is the compiled validator.
    $$(compile [|| validateDateTyped ||])
    -- The second argument is a compiled wrapper.
    -- Unfortunately we can't just inline wrapValidator here for technical reasons.
    $$(compile [|| wrap ||])
    where
        wrap = wrapValidator

dateValidatorHash :: ValidatorHash
dateValidatorHash = scriptHash dateInstance

dateValidator :: Validator
dateValidator = validatorScript dateInstance


user2201: Although there may have been changes, this remains a valid question.
The code shown in the question is the boilerplate code that accompanies a validator implementation for on-chain execution. A simple validator implementation can be seen below. It is the recent 42 redeemer validator code of Pioneer (before switch from Data to BuildinData).
-- This is the validator implementation
-- It must be inlinable so it can be compiled into Plutus code
{-# INLINABLE mkValidator #-}
mkValidator :: Data -> Data -> Data -> ()
mkValidator _ r _
    | r == I 42 = ()
    | otherwise = traceError "wrong redeemer"

-- boilerplate: compiles validator to Plutus code
validator :: Validator
validator = mkValidatorScript $$(PlutusTx.compile [|| mkValidator ||])

-- boilerplate: get the hash of the validator script
valHash :: Ledger.ValidatorHash
valHash = Scripts.validatorHash validator

-- boilerplate: get the script address of the validator
scrAddress :: Ledger.Address
scrAddress = scriptAddress validator

The first code block is the validator implementation in Haskell, here named mkValidator.
The actual question refers to the next three code blocks marked as boilerplate.
validator inlines the mkValidator implementation and compiles it to Plutus code. This is necessary so the validator can be executed on-chain.
valHash and scrAddress are auxiliary functions that return hash and address of the the validator script.
One can see them used in the off-chain code to construct the transactions.
The reason for this roundabout way of implementing the validator is to enable code sharing between on-chain and off-chain executed code.
More complex validator implementations will result in a more complex Plutus code compiler code block, but the principle remains the same.

1679: <p>I need someone to explain to me line by line. The code is from plutu tutorials. <a href="https://docs.cardano.org/projects/plutus/en/latest/plutus/tutorials/basic-validators.html" rel="noreferrer">https://docs.cardano.org/projects/plutus/en/latest/plutus/tutorials/basic-validators.html</a></p>
<p>All the code in that page I can understand. Except the last one. I don't really get it. the code that I don't understand:</p>
<pre><code>dateInstance :: ScriptInstance DateValidator
dateInstance = validator @DateValidator
    -- The first argument is the compiled validator.
    $$(compile [|| validateDateTyped ||])
    -- The second argument is a compiled wrapper.
    -- Unfortunately we can't just inline wrapValidator here for technical reasons.
    $$(compile [|| wrap ||])
    where
        wrap = wrapValidator

dateValidatorHash :: ValidatorHash
dateValidatorHash = scriptHash dateInstance

dateValidator :: Validator
dateValidator = validatorScript dateInstance
</code></pre>
 2201: <p>Although there may have been changes, this remains a valid question.<br />
The code shown in the question is the boilerplate code that accompanies a validator implementation for on-chain execution. A simple validator implementation can be seen below. It is the recent 42 redeemer validator code of Pioneer (before switch from <code>Data</code> to <code>BuildinData</code>).</p>
<pre><code>-- This is the validator implementation
-- It must be inlinable so it can be compiled into Plutus code
{-# INLINABLE mkValidator #-}
mkValidator :: Data -&gt; Data -&gt; Data -&gt; ()
mkValidator _ r _
    | r == I 42 = ()
    | otherwise = traceError &quot;wrong redeemer&quot;

-- boilerplate: compiles validator to Plutus code
validator :: Validator
validator = mkValidatorScript $$(PlutusTx.compile [|| mkValidator ||])

-- boilerplate: get the hash of the validator script
valHash :: Ledger.ValidatorHash
valHash = Scripts.validatorHash validator

-- boilerplate: get the script address of the validator
scrAddress :: Ledger.Address
scrAddress = scriptAddress validator
</code></pre>
<p>The first code block is the validator implementation in Haskell, here named <code>mkValidator</code>.</p>
<p>The actual question refers to the next three code blocks marked as boilerplate.<br />
<code>validator</code> inlines the <code>mkValidator</code> implementation and compiles it to Plutus code. This is necessary so the validator can be executed on-chain.<br />
<code>valHash</code> and <code>scrAddress</code> are auxiliary functions that return hash and address of the the validator script.<br />
One can see them used in the off-chain code to construct the transactions.</p>
<p>The reason for this roundabout way of implementing the validator is to enable code sharing between on-chain and off-chain executed code.</p>
<p>More complex validator implementations will result in a more complex Plutus code compiler code block, but the principle remains the same.</p>
