SlideShare a Scribd company logo
1 of 35
Download to read offline
Modular Module Systems:
        a survey

      Christopher League
            LIU Brooklyn



      Northeast Scala Symposium
             March 
What is a module?




© Miran Lipovača, Learn You a Haskell for Great Good!
  http://learnyouahaskell.com/ (By-NC-SA)
What is a module?
What is a module?
. Separate compilation
. Namespace management
. Hiding / abstraction
Separate compilation in C
“module” == file
#include <stdio.h>
declarations
extern int foo;
vs. definitions
int foo = 40;
Namespace management in C
Hiding only, to limit namespace pollution
static void dont_export_me_bro()
{
    //...
}
Namespace management in C++
Nesting, scope operator, imports, limited renaming
namespace greenfield { }
using namespace std;
using greenfield::cout;
namespace magick = future::tech;
magick::dwim();
Abstract data types in C
Opaque type declaration (∃), void* (∀?)
struct stack;
stack* new_stack();
void push (stack*, void*);
Type abstraction in C++
Generics (∀ T such that ???)
template<class T>
T& findMin(T* array, int size);
Hiding in C++
Member access control
class Foo {
private:
  int x;
};
Hiding in C++
Privacy via subsumption
struct stack {
    virtual void push(int) = 0;
    virtual int pop() = 0;
    static stack* create();
};
struct stackImpl : public stack {
    int a[SIZE];
    int k;
    // ...
};
Modules in Haskell
“Haskell’s module design is relatively conservative”
                       — A Gentle Introduction to Haskell
module Utility.StatFS(
    FileSystemStats(..),
    getFileSystemStats) where

import Data.ByteString
import Data.ByteString.Char8 (pack)
import qualified Foreign as F

getFileSystemStats ::
    String -> IO (Maybe FileSystemStats)
getFileSystemStats path = {- ... -}

data FileSystemStats = {- ... -}
Type classes in Haskell
class Arbitrary a where
  arbitrary :: Gen a

instance Arbitrary Bool where
  arbitrary = choose (False,True)

instance (Arbitrary a, Arbitrary b) => Arbitrary (a,b)
  where
    arbitrary = liftM2 (,) arbitrary arbitrary

prn :: (Arbitrary a, Show a) => a -> IO ()
Signatures
    Type declarations and value specifications
signature COLLECTION = sig
    type ’a t
    val empty: ’a t
    val isEmpty: ’a t -> bool
end
signature QUEUE = sig
    type ’a t
    val enqueue: ’a * ’a t -> ’a t
    val dequeue: ’a t -> (’a t * ’a) option
end
signature DEQUE = sig
    include COLLECTION
    structure Front: QUEUE where type ’a t = ’a t
    structure Rear: QUEUE where type ’a t = ’a t
end
Structures
    Nested collections of defs, constrained by sigs
structure Deque :> DEQUE = struct
    type ’a t = ’a list * ’a list
    val empty = (nil, nil)
    fun isEmpty (nil, nil) = true
      | isEmpty _ = false
    structure Front = struct
        type ’a t = ’a t
        fun enqueue (x, (rs,fs)) = (rs, x::fs)
        fun dequeue (nil, nil) = NONE
          | dequeue (rs, x::fs) = SOME ((rs,fs), x)
          | dequeue (rs, nil) = dequeue (nil, rev rs)
    end
    structure Rear = struct (* ... *) end
end
Functors
    Structures parameterized by structures
    Not the thing from category theory, Haskell
functor TestDeque(D: DEQUE) = struct
    val q1 = D.empty
    val q2 = D.Front.enqueue (3, q1)
    val q3 = D.Front.enqueue (2, q2)
    val q4 = D.Rear.enqueue (4, q3)
    val q5 = D.Rear.enqueue (5, q4)
    (* ... *)
end

structure T = TestDeque(Deque)
‘Functorized’ style in ML
    Lift most structure dependencies
    to functor parameters
functor CompileF(M : CODEGENERATOR): COMPILE0 = ...
functor EvalLoopF(Compile: TOP_COMPILE) : EVALLOOP = ...
functor Interact(EvalLoop : EVALLOOP) : INTERACT = ...

    Instantiate dependencies at ‘link time’
structure Interact =
  Interact(EvalLoopF(CompileF(X86MC)))
A signature for mutable graphs
Parameterize by type representing Vertex, Edge.
trait DirectedGraphSig {
  trait Graph[V,E] {
    def vertices: Iterator[V]
    def successors(v: V): Iterator[(V,E)]
    def add(v: V)
    def contains(v: V): Boolean
    def add(v1: V, v2: V, e: E)
    def get(v1: V, v2: V): Option[E]
  }
  def create[V,E]: Graph[V,E]
}
Yes, mutable — sorry
import scala.collection.generic.MutableMapFactory
import scala.collection.generic.MutableSetFactory
import scala.collection.mutable._
Representing graphs
Adjacency list vs. adjacency matrix




In general: V → V → E
Building graphs from maps
class DirectedGraphFun[
  M1[A,B] <: Map[A,B] with MapLike[A,B,M1[A,B]],
  M2[A,B] <: Map[A,B] with MapLike[A,B,M2[A,B]]]
 (MF1: MutableMapFactory[M1],
  MF2: MutableMapFactory[M2])
extends DirectedGraphSig
{
  class GraphImpl[V,E] extends Graph[V,E] {
    private val rep: M1[V,M2[V,E]] = MF1.empty
    // ...
  }
  def create[V,E] = new GraphImpl[V,E]
}
Instantiating the ‘functor’
object AdjacencyList
extends DirectedGraphFun[
  HashMap, ListMap](HashMap, ListMap)

object AdjacencyMatrix
extends DirectedGraphFun[
  HashMap, HashMap](HashMap, HashMap)

    Easily build new modules with different space-time
    characteristics
Inspiration from C++ STL
#include <algorithm>
Graph search implementation
class GraphSearchFun[
  S[A] <: Set[A] with SetLike[A,S[A]]]
  (S: MutableSetFactory[S],
   WL: WorkListSig)
{
  type Path[V,E] = List[(V,E)]
  def search[V,E](g: DirectedGraphSig#Graph[V,E],
                   origin: V,
                   f: (V, Path[V,E]) => Unit) {
    val visited = S.empty[V]
    val work = WL.create[(V,Path[V,E])]
    work.put((origin, Nil))
    while(!work.isEmpty) {
      val (v1, path1) = work.take
      // ...
    }
Graph search relies on a work list
trait WorkListSig {
  trait WorkList[T] {
    def isEmpty: Boolean
    def put(x: T)
    def take: T
  }
  def create[T]: WorkList[T]
}
Various work list strategies
object LIFO extends WorkListSig {
  trait StackAsWorkList[T]
  extends Stack[T] with WorkList[T]   {
    def put(x: T) = push(x)
    def take: T = pop
  }
  def create[T] = new Stack[T] with   StackAsWorkList[T]
}
object FIFO extends WorkListSig {
  trait QueueAsWorkList[T]
  extends Queue[T] with WorkList[T]   {
    def put(x: T) = enqueue(x)
    def take: T = dequeue
  }
  def create[T] = new Queue[T] with   QueueAsWorkList[T]
}
Voilà — different search algorithms
object BFS
extends GraphSearchFun[Set](Set, FIFO)

object DFS
extends GraphSearchFun[Set](Set, LIFO)
class ExampleFun[G <: DirectedGraphSig](G: G) {
  def example: G#Graph[String,Int] = {
    val g = G.create[String,Int]
    g.add(”A”, ”B”, 2); g.add(”A”, ”C”, 3)
    g.add(”A”, ”D”, 1); g.add(”G”, ”C”, 4)
    g.add(”D”, ”H”, 3); g.add(”D”, ”I”, 2)
    g.add(”E”, ”F”, 3); g.add(”G”, ”F”, 2)
    g.add(”H”, ”G”, 5); g.add(”I”, ”J”, 1)
    g.add(”J”, ”K”, 6); g.add(”K”, ”G”, 2)
    g.add(”K”, ”L”, 1)
    g
  }
BFS on   AdjacencyList                               DFS on AdjacencyMatrix
A from   List()                                      A from List()
D from   List((A,1))                                 B from List((A,2))
C from   List((A,3))                                 D from List((A,1))
B from   List((A,2))                                 I from List((D,2), (A,1))
I from   List((D,2), (A,1))                          J from List((I,1), (D,2), (A,1))
H from   List((D,3), (A,1))                          K from List((J,6), (I,1), (D,2), (A,1))
J from   List((I,1), (D,2),   (A,1))                 G from List((K,2), (J,6), (I,1), (D,2), (A,1))
G from   List((H,5), (D,3),   (A,1))                 F from List((G,2), (K,2), (J,6), (I,1), (D,2), (A,1))
K from   List((J,6), (I,1),   (D,2), (A,1))          C from List((G,4), (K,2), (J,6), (I,1), (D,2), (A,1))
F from   List((G,2), (H,5),   (D,3), (A,1))          L from List((K,1), (J,6), (I,1), (D,2), (A,1))
L from   List((K,1), (J,6),   (I,1), (D,2), (A,1))   H from List((D,3), (A,1))
Untyped → typed
Traits from Smalltalk, Self
Flavors, mixins from CLOS
Untyped → typed
“It was not obvious how to combine the C++ strong static
 type checking with a scheme flexible enough to support
 directly the ‘mixin’ style of programming used in some
 LISP dialects.”
Untyped → typed ?
anks!
       league@contrapunctus.net
             @chrisleague

Code and slides will be made available later

More Related Content

What's hot

Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a categorysamthemonad
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Philip Schwarz
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!priort
 
Fp in scala part 1
Fp in scala part 1Fp in scala part 1
Fp in scala part 1Hang Zhao
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional ProgrammingLuka Jacobowitz
 
Monoids - Part 2 - with examples using Scalaz and Cats
Monoids - Part 2 - with examples using Scalaz and CatsMonoids - Part 2 - with examples using Scalaz and Cats
Monoids - Part 2 - with examples using Scalaz and CatsPhilip Schwarz
 
Abstracting over the Monad yielded by a for comprehension and its generators
Abstracting over the Monad yielded by a for comprehension and its generatorsAbstracting over the Monad yielded by a for comprehension and its generators
Abstracting over the Monad yielded by a for comprehension and its generatorsPhilip Schwarz
 
Fp in scala with adts part 2
Fp in scala with adts part 2Fp in scala with adts part 2
Fp in scala with adts part 2Hang Zhao
 
Simple IO Monad in 'Functional Programming in Scala'
Simple IO Monad in 'Functional Programming in Scala'Simple IO Monad in 'Functional Programming in Scala'
Simple IO Monad in 'Functional Programming in Scala'Philip Schwarz
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Philip Schwarz
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
The Next Great Functional Programming Language
The Next Great Functional Programming LanguageThe Next Great Functional Programming Language
The Next Great Functional Programming LanguageJohn De Goes
 
Data structures in scala
Data structures in scalaData structures in scala
Data structures in scalaMeetu Maltiar
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In ScalaSkills Matter
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FPLuka Jacobowitz
 

What's hot (20)

Stack queue
Stack queueStack queue
Stack queue
 
Monad presentation scala as a category
Monad presentation   scala as a categoryMonad presentation   scala as a category
Monad presentation scala as a category
 
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
Quicksort - a whistle-stop tour of the algorithm in five languages and four p...
 
Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!Beginning Haskell, Dive In, Its Not That Scary!
Beginning Haskell, Dive In, Its Not That Scary!
 
Fp in scala part 1
Fp in scala part 1Fp in scala part 1
Fp in scala part 1
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
 
Monoids - Part 2 - with examples using Scalaz and Cats
Monoids - Part 2 - with examples using Scalaz and CatsMonoids - Part 2 - with examples using Scalaz and Cats
Monoids - Part 2 - with examples using Scalaz and Cats
 
Abstracting over the Monad yielded by a for comprehension and its generators
Abstracting over the Monad yielded by a for comprehension and its generatorsAbstracting over the Monad yielded by a for comprehension and its generators
Abstracting over the Monad yielded by a for comprehension and its generators
 
Lec4
Lec4Lec4
Lec4
 
Fp in scala with adts part 2
Fp in scala with adts part 2Fp in scala with adts part 2
Fp in scala with adts part 2
 
Simple IO Monad in 'Functional Programming in Scala'
Simple IO Monad in 'Functional Programming in Scala'Simple IO Monad in 'Functional Programming in Scala'
Simple IO Monad in 'Functional Programming in Scala'
 
Functor Composition
Functor CompositionFunctor Composition
Functor Composition
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
The Next Great Functional Programming Language
The Next Great Functional Programming LanguageThe Next Great Functional Programming Language
The Next Great Functional Programming Language
 
Monads do not Compose
Monads do not ComposeMonads do not Compose
Monads do not Compose
 
Data structures in scala
Data structures in scalaData structures in scala
Data structures in scala
 
Stack, queue and hashing
Stack, queue and hashingStack, queue and hashing
Stack, queue and hashing
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In Scala
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FP
 

Viewers also liked

Becta next generation conference 2010
Becta next generation conference 2010Becta next generation conference 2010
Becta next generation conference 2010Zak Mensah
 
Merits of good design - Plymouth e-learning conference
Merits of good design - Plymouth e-learning conference Merits of good design - Plymouth e-learning conference
Merits of good design - Plymouth e-learning conference Zak Mensah
 
using digital media @ Leicester college
using digital media @ Leicester collegeusing digital media @ Leicester college
using digital media @ Leicester collegeZak Mensah
 
Establishing the digital City limits
Establishing the digital City limitsEstablishing the digital City limits
Establishing the digital City limitsZak Mensah
 
Benefits of using digital media for training
Benefits of using digital media for trainingBenefits of using digital media for training
Benefits of using digital media for trainingZak Mensah
 
Jisc Content Conference 30th june - 1st july 2009
Jisc Content Conference 30th june - 1st july 2009Jisc Content Conference 30th june - 1st july 2009
Jisc Content Conference 30th june - 1st july 2009Zak Mensah
 
Programming Android
Programming AndroidProgramming Android
Programming Androidleague
 

Viewers also liked (7)

Becta next generation conference 2010
Becta next generation conference 2010Becta next generation conference 2010
Becta next generation conference 2010
 
Merits of good design - Plymouth e-learning conference
Merits of good design - Plymouth e-learning conference Merits of good design - Plymouth e-learning conference
Merits of good design - Plymouth e-learning conference
 
using digital media @ Leicester college
using digital media @ Leicester collegeusing digital media @ Leicester college
using digital media @ Leicester college
 
Establishing the digital City limits
Establishing the digital City limitsEstablishing the digital City limits
Establishing the digital City limits
 
Benefits of using digital media for training
Benefits of using digital media for trainingBenefits of using digital media for training
Benefits of using digital media for training
 
Jisc Content Conference 30th june - 1st july 2009
Jisc Content Conference 30th june - 1st july 2009Jisc Content Conference 30th june - 1st july 2009
Jisc Content Conference 30th june - 1st july 2009
 
Programming Android
Programming AndroidProgramming Android
Programming Android
 

Similar to Modular Module Systems

Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patternsleague
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsJohn De Goes
 
The Essence of the Iterator Pattern
The Essence of the Iterator PatternThe Essence of the Iterator Pattern
The Essence of the Iterator PatternEric Torreborre
 
The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)Eric Torreborre
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
The java language cheat sheet
The java language cheat sheetThe java language cheat sheet
The java language cheat sheetanand_study
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed worldDebasish Ghosh
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
Algebraic Data Types and Origami Patterns
Algebraic Data Types and Origami PatternsAlgebraic Data Types and Origami Patterns
Algebraic Data Types and Origami PatternsVasil Remeniuk
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programmingLukasz Dynowski
 
FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳Yuri Inoue
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 

Similar to Modular Module Systems (20)

Array
ArrayArray
Array
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
 
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & AnalyticsQuark: A Purely-Functional Scala DSL for Data Processing & Analytics
Quark: A Purely-Functional Scala DSL for Data Processing & Analytics
 
The Essence of the Iterator Pattern
The Essence of the Iterator PatternThe Essence of the Iterator Pattern
The Essence of the Iterator Pattern
 
The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)
 
purrr.pdf
purrr.pdfpurrr.pdf
purrr.pdf
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
The java language cheat sheet
The java language cheat sheetThe java language cheat sheet
The java language cheat sheet
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Algebraic Data Types and Origami Patterns
Algebraic Data Types and Origami PatternsAlgebraic Data Types and Origami Patterns
Algebraic Data Types and Origami Patterns
 
Python 101 language features and functional programming
Python 101 language features and functional programmingPython 101 language features and functional programming
Python 101 language features and functional programming
 
Java cheatsheet
Java cheatsheetJava cheatsheet
Java cheatsheet
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Practical cats
Practical catsPractical cats
Practical cats
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳FP in scalaで鍛える関数型脳
FP in scalaで鍛える関数型脳
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 

Recently uploaded

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Modular Module Systems

  • 1. Modular Module Systems: a survey Christopher League LIU Brooklyn Northeast Scala Symposium  March 
  • 2. What is a module? © Miran Lipovača, Learn You a Haskell for Great Good! http://learnyouahaskell.com/ (By-NC-SA)
  • 3. What is a module?
  • 4. What is a module? . Separate compilation . Namespace management . Hiding / abstraction
  • 5. Separate compilation in C “module” == file #include <stdio.h> declarations extern int foo; vs. definitions int foo = 40;
  • 6. Namespace management in C Hiding only, to limit namespace pollution static void dont_export_me_bro() { //... }
  • 7. Namespace management in C++ Nesting, scope operator, imports, limited renaming namespace greenfield { } using namespace std; using greenfield::cout; namespace magick = future::tech; magick::dwim();
  • 8. Abstract data types in C Opaque type declaration (∃), void* (∀?) struct stack; stack* new_stack(); void push (stack*, void*);
  • 9. Type abstraction in C++ Generics (∀ T such that ???) template<class T> T& findMin(T* array, int size);
  • 10. Hiding in C++ Member access control class Foo { private: int x; };
  • 11. Hiding in C++ Privacy via subsumption struct stack { virtual void push(int) = 0; virtual int pop() = 0; static stack* create(); }; struct stackImpl : public stack { int a[SIZE]; int k; // ... };
  • 12. Modules in Haskell “Haskell’s module design is relatively conservative” — A Gentle Introduction to Haskell module Utility.StatFS( FileSystemStats(..), getFileSystemStats) where import Data.ByteString import Data.ByteString.Char8 (pack) import qualified Foreign as F getFileSystemStats :: String -> IO (Maybe FileSystemStats) getFileSystemStats path = {- ... -} data FileSystemStats = {- ... -}
  • 13. Type classes in Haskell class Arbitrary a where arbitrary :: Gen a instance Arbitrary Bool where arbitrary = choose (False,True) instance (Arbitrary a, Arbitrary b) => Arbitrary (a,b) where arbitrary = liftM2 (,) arbitrary arbitrary prn :: (Arbitrary a, Show a) => a -> IO ()
  • 14.
  • 15. Signatures Type declarations and value specifications signature COLLECTION = sig type ’a t val empty: ’a t val isEmpty: ’a t -> bool end signature QUEUE = sig type ’a t val enqueue: ’a * ’a t -> ’a t val dequeue: ’a t -> (’a t * ’a) option end signature DEQUE = sig include COLLECTION structure Front: QUEUE where type ’a t = ’a t structure Rear: QUEUE where type ’a t = ’a t end
  • 16. Structures Nested collections of defs, constrained by sigs structure Deque :> DEQUE = struct type ’a t = ’a list * ’a list val empty = (nil, nil) fun isEmpty (nil, nil) = true | isEmpty _ = false structure Front = struct type ’a t = ’a t fun enqueue (x, (rs,fs)) = (rs, x::fs) fun dequeue (nil, nil) = NONE | dequeue (rs, x::fs) = SOME ((rs,fs), x) | dequeue (rs, nil) = dequeue (nil, rev rs) end structure Rear = struct (* ... *) end end
  • 17. Functors Structures parameterized by structures Not the thing from category theory, Haskell functor TestDeque(D: DEQUE) = struct val q1 = D.empty val q2 = D.Front.enqueue (3, q1) val q3 = D.Front.enqueue (2, q2) val q4 = D.Rear.enqueue (4, q3) val q5 = D.Rear.enqueue (5, q4) (* ... *) end structure T = TestDeque(Deque)
  • 18. ‘Functorized’ style in ML Lift most structure dependencies to functor parameters functor CompileF(M : CODEGENERATOR): COMPILE0 = ... functor EvalLoopF(Compile: TOP_COMPILE) : EVALLOOP = ... functor Interact(EvalLoop : EVALLOOP) : INTERACT = ... Instantiate dependencies at ‘link time’ structure Interact = Interact(EvalLoopF(CompileF(X86MC)))
  • 19. A signature for mutable graphs Parameterize by type representing Vertex, Edge. trait DirectedGraphSig { trait Graph[V,E] { def vertices: Iterator[V] def successors(v: V): Iterator[(V,E)] def add(v: V) def contains(v: V): Boolean def add(v1: V, v2: V, e: E) def get(v1: V, v2: V): Option[E] } def create[V,E]: Graph[V,E] }
  • 20. Yes, mutable — sorry import scala.collection.generic.MutableMapFactory import scala.collection.generic.MutableSetFactory import scala.collection.mutable._
  • 21. Representing graphs Adjacency list vs. adjacency matrix In general: V → V → E
  • 22. Building graphs from maps class DirectedGraphFun[ M1[A,B] <: Map[A,B] with MapLike[A,B,M1[A,B]], M2[A,B] <: Map[A,B] with MapLike[A,B,M2[A,B]]] (MF1: MutableMapFactory[M1], MF2: MutableMapFactory[M2]) extends DirectedGraphSig { class GraphImpl[V,E] extends Graph[V,E] { private val rep: M1[V,M2[V,E]] = MF1.empty // ... } def create[V,E] = new GraphImpl[V,E] }
  • 23. Instantiating the ‘functor’ object AdjacencyList extends DirectedGraphFun[ HashMap, ListMap](HashMap, ListMap) object AdjacencyMatrix extends DirectedGraphFun[ HashMap, HashMap](HashMap, HashMap) Easily build new modules with different space-time characteristics
  • 24. Inspiration from C++ STL #include <algorithm>
  • 25. Graph search implementation class GraphSearchFun[ S[A] <: Set[A] with SetLike[A,S[A]]] (S: MutableSetFactory[S], WL: WorkListSig) { type Path[V,E] = List[(V,E)] def search[V,E](g: DirectedGraphSig#Graph[V,E], origin: V, f: (V, Path[V,E]) => Unit) { val visited = S.empty[V] val work = WL.create[(V,Path[V,E])] work.put((origin, Nil)) while(!work.isEmpty) { val (v1, path1) = work.take // ... }
  • 26. Graph search relies on a work list trait WorkListSig { trait WorkList[T] { def isEmpty: Boolean def put(x: T) def take: T } def create[T]: WorkList[T] }
  • 27. Various work list strategies object LIFO extends WorkListSig { trait StackAsWorkList[T] extends Stack[T] with WorkList[T] { def put(x: T) = push(x) def take: T = pop } def create[T] = new Stack[T] with StackAsWorkList[T] } object FIFO extends WorkListSig { trait QueueAsWorkList[T] extends Queue[T] with WorkList[T] { def put(x: T) = enqueue(x) def take: T = dequeue } def create[T] = new Queue[T] with QueueAsWorkList[T] }
  • 28. Voilà — different search algorithms object BFS extends GraphSearchFun[Set](Set, FIFO) object DFS extends GraphSearchFun[Set](Set, LIFO)
  • 29. class ExampleFun[G <: DirectedGraphSig](G: G) { def example: G#Graph[String,Int] = { val g = G.create[String,Int] g.add(”A”, ”B”, 2); g.add(”A”, ”C”, 3) g.add(”A”, ”D”, 1); g.add(”G”, ”C”, 4) g.add(”D”, ”H”, 3); g.add(”D”, ”I”, 2) g.add(”E”, ”F”, 3); g.add(”G”, ”F”, 2) g.add(”H”, ”G”, 5); g.add(”I”, ”J”, 1) g.add(”J”, ”K”, 6); g.add(”K”, ”G”, 2) g.add(”K”, ”L”, 1) g }
  • 30. BFS on AdjacencyList DFS on AdjacencyMatrix A from List() A from List() D from List((A,1)) B from List((A,2)) C from List((A,3)) D from List((A,1)) B from List((A,2)) I from List((D,2), (A,1)) I from List((D,2), (A,1)) J from List((I,1), (D,2), (A,1)) H from List((D,3), (A,1)) K from List((J,6), (I,1), (D,2), (A,1)) J from List((I,1), (D,2), (A,1)) G from List((K,2), (J,6), (I,1), (D,2), (A,1)) G from List((H,5), (D,3), (A,1)) F from List((G,2), (K,2), (J,6), (I,1), (D,2), (A,1)) K from List((J,6), (I,1), (D,2), (A,1)) C from List((G,4), (K,2), (J,6), (I,1), (D,2), (A,1)) F from List((G,2), (H,5), (D,3), (A,1)) L from List((K,1), (J,6), (I,1), (D,2), (A,1)) L from List((K,1), (J,6), (I,1), (D,2), (A,1)) H from List((D,3), (A,1))
  • 31. Untyped → typed Traits from Smalltalk, Self Flavors, mixins from CLOS
  • 32.
  • 33. Untyped → typed “It was not obvious how to combine the C++ strong static type checking with a scheme flexible enough to support directly the ‘mixin’ style of programming used in some LISP dialects.”
  • 35. anks! league@contrapunctus.net @chrisleague Code and slides will be made available later