Primitive derivatives and combinators in EDSL: s

I recently passed the exam, mainly due to an EDSL question. I did not understand these concepts, so I think why I failed. I think the explanation of my teachers was abstract for me, so I wonder if anyone can explain it more clearly.

I wonder if anyone can briefly explain what EDSL components are and what characterize them. In our course, we went through Shallow and Deep Embedding from DSL and looked at the following building blocks for DSL:

  • Constructor functions
  • Combinators (primitive and derivative)
  • Launch functions

I think the contructor and run functions are more understandable, so I'm more interested in understanding what makes a combinator derivative or primitive. It doesn’t hurt if someone explains other concepts. Here is an example from our lectures for reference. Its shallow implementation of DSL for creating signals:

module Signal.Shallow
( Time
-- | the 'Signal' type is abstract
, Signal  
-- * Smart constructors
, constS, timeS
-- * Combinators
, ($$), mapT
-- * Derived operation
, mapS
-- * Run function
, sample
) where

-- * Smart constructors
constS :: a -> Signal a
timeS  ::      Signal Time
-- * Combinators
($$)   :: Signal (a -> b) -> Signal a -> Signal b
mapT   :: (Time -> Time)  -> Signal a -> Signal a
-- * Derived operation
mapS   :: (a -> b)        -> Signal a -> Signal b
-- * Run function
sample :: Signal a -> Time -> a  

type Time = Double
newtype Signal a = Sig {unSig :: Time -> a}

-- | The constant signal.
constS x = Sig (const x)

-- | The time signal
timeS = Sig id

-- | Function application lifted to signals.
fs $$ xs = Sig (\t -> unSig fs t  (unSig xs t))
+4
source share
1 answer

A primitive combinator is one that is embedded in a DSL defined in a base language (e.g. Haskell). DSLs are often built around an abstract type -a, whose implementation is hidden to the end user. It is completely opaque. Primitive combinators represented by the language are those who need to know how abstraction is actually implemented to work.

, DSL. . , - , .

Haskell. , Int Int, + . , , , , . , Bool ; .

data Bool = True | False -- ... you can't do this for Int!

"" "" DSL - , , - Haskell.

Signal . Time -> a, . ( DSL) Signal. (, , : Double, .)

$$ , , Signal Time -> a. Signal, $$. , $$ .

, mapS , , . Signal . :

mapS f signal = constS f $$ signal

, constS $$, Signal. , , . mapS "", DSL, . Signal, mapS - : constS $$, mapS .

: - , . - . , .

+4

All Articles