The document discusses type-level programming in Scala. It covers several type-level programming techniques including:
1. Type safe equality using an implicit class StrictEq to define === operator that checks equality at compile time.
2. Builder pattern using phantom types to encode constraints and only allow building of valid objects.
3. Type class pattern to define type-parameterized behaviors like addition using an Adder trait and implicit instances.
4. Literal types to encode additional meaning to values like 42.type.
5. Dependent types where a type may depend on a value, like a type parameter a in a.B.
James Kyle is a member of the Babel team and a UI Engineer at CloudFlare.
In this talk he'll walk through how Babel is designed from the ground up.
Then a quick dive into how you can use it to create custom tooling that will help you write better software.
James Kyle is a member of the Babel team and a UI Engineer at CloudFlare.
In this talk he'll walk through how Babel is designed from the ground up.
Then a quick dive into how you can use it to create custom tooling that will help you write better software.
Learning iOS development using Swift (Arabic tutorials) - Third session slides, which covers the following topics:
- Classes and Structures
- Properties
- Methods
- Access Control
- Inheritance
- Initialization
- Deinitialization
- Protocols
The video concludes with a demo of screen transitions and view controller lifecycle.
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...James Titcumb
Have you ever used PHP’s built in reflection, only to find you can’t do quite what you wanted? What about finding types for parameters or properties? What about reflecting on classes that aren’t loaded, so that you can modify them directly?
Better Reflection is an awesome new library that uses magical time-warp techniques* to improve on PHP’s built-in reflection by providing additional functionality. In this talk we’ll cover what reflection is all about, explore the cool features of Better Reflection already implemented, the difficulties we faced actually writing the thing, and how you can use Better Reflection in your projects to maximise your reflection-fu.
(*actual magic or time-warp not guaranteed)
ECMA5 approach to building JavaScript frameworks with Anzor BashkhazFITC
Save 10% off ANY FITC event with discount code 'slideshare'
See our upcoming events at www.fitc.ca
ECMA5 has given JavaScript a number of new ways to define and manipulate objects. In this session, attendees will learn how to combine Require.js and ECMA5’s object manipulation functions to create an inheritance model similar to class-based languages.
This session will introduce you to the new Form component in Symfony2. With the new domain-driven paradigma and its flexible design, the component opens a door to a wide range of possibilities. The brand new architecture makes creating complex forms easier and faster than ever before. This talk will teach you today what you need to know to build powerful forms tomorrow.
Building Reusable Custom Elements With AngularIlia Idakiev
What are Web Components and how we use them. What is Angular Elements and how can we package our angular components as custom elements and reuse them everywhere.
Demos: https://github.com/iliaidakiev/slides/
Sketchmine is a toolset to maintain, validate and create Sketch files. The perfect suite for design systems and design systems tooling. In this presentation, we look at challenges of large organisations and their design systems, and how we solve them with Sketchmine. Design Ops as it should be
Everything you always wanted to know about forms* *but were afraid to askAndrea Giuliano
La componente dei Form di Symfony2 rende possibile la costruzione di diverse tipologie di form in modo del tutto semplice. La sua architettura flessibile e altamente scalabile permette di poter gestire strutture adatte ad ogni tipo di esigenza. Tuttavia, conoscere come utilizzare appieno tutta la sua potenza non è banale. In questo talk verrà trattato in profondità la componente Form di Symfony2, mostrando i suoi meccanismi di base e come utilizzarli per estenderli ed introdurre la propria logica di business, così da costruire form cuciti a misura delle tue necessità.
Android Developer Group Poznań - Kotlin for Android developers
STXInsider example project in Kotlin:
https://github.com/kosiara/stx-insider
Kotlin - one of the popular programming languages built on top of Java that runs on JVM. Thanks to JetBrains support and excellent IDE integration, it’s an ideal choice for Android development. 100% Java compatibility, interoperability and no runtime overhead is just the beginning of a long list of strengths. Kotlin is supposed to be a subset of SCALA, has clear benefits for developers on one hand and keeps short compile times on the other.
As a mobile team we got interested in Kotlin a few months before its final release which gave us time to test it thoroughly before production use. The language has some clear advantages for an Android programmer - it enables migration from Java projects that have been under development for some time already. Java&Kotlin coexistence simplifies Kotlin introduction as only new functionality is written in JetBrain’s new language leaving all the legacy code untouched.
Transitioning gives the developer an opportunity to use lambdas, new syntax for data objects, extension functions to easily expand Android SDK’s classes functionality and infix notation to write DSL-like structures. Almost all the libraries you use today will work with Kotlin thanks to 100% Java compatibility. The same is true for Android SDK classes - all of them will seamlessly work with the new programming language. Kotlin gives you more choice when it comes to reflection, creating documentation and being null-pointer safe. Android works great with it out of the box so you won’t need to change your development habits.
Our production project in Kotlin turned out to be a success after 4 months of development. We had 0 bugs related to Kotlin as a programming language. Our code footprint is almost 30% smaller thanks to JetBrain’s, we benefit from nullpointer safety, closures, translated enums, data objects and use infix notation for logging and displaying Snackbars.
===========
In this presentation you'll find basic use cases, syntax, structures and patterns. Later on Kotlin is presented in Android context. Simple project structure, imports and Kotlin usage with Android SDK is explained. In the end cost of Kotlin compilation is presented and the language is compared to SCALA and SWIFT.
We look at the positive impact new syntax can have on boilerplate removal and readability improvement.
Kotlin really shines in Android development when one looks at “Enum translation”, “Extension functions”, “SAM conversions”, “Infix notation”, “Closures” and “Fluent interfaces” applied to lists. The talk, however, compares language-specifics of Java & Kotlin in terms of “Type Variance”, “Generics” and “IDE tools” as well.
In this chapter we will understand how to define custom classes and their elements. We will learn to declare fields, constructors and properties for the classes. We will revise what a method is and we will broaden our knowledge about access modifiers and methods.
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
In this session, we will present real life applications of compiler techniques helping kaChing achieve ultra confidence and power its incredible 5 minutes commit-to-production cycle [1]. We'll talk about idempotency analysis [2], dependency detection, on the fly optimisations, automatic memoization [3], type unification [4] and more! This talk is not suitable for the faint-hearted... If you want to dive deep, learn about advanced JVM topics, devoure bytecode and see first hand applications of theoretical computer science, join us.
[1] http://eng.kaching.com/2010/05/deployment-infrastructure-for.html
[2] http://en.wikipedia.org/wiki/Idempotence
[3] http://en.wikipedia.org/wiki/Memoization
[4] http://eng.kaching.com/2009/10/unifying-type-parameters-in-java.html
Learning iOS development using Swift (Arabic tutorials) - Third session slides, which covers the following topics:
- Classes and Structures
- Properties
- Methods
- Access Control
- Inheritance
- Initialization
- Deinitialization
- Protocols
The video concludes with a demo of screen transitions and view controller lifecycle.
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...James Titcumb
Have you ever used PHP’s built in reflection, only to find you can’t do quite what you wanted? What about finding types for parameters or properties? What about reflecting on classes that aren’t loaded, so that you can modify them directly?
Better Reflection is an awesome new library that uses magical time-warp techniques* to improve on PHP’s built-in reflection by providing additional functionality. In this talk we’ll cover what reflection is all about, explore the cool features of Better Reflection already implemented, the difficulties we faced actually writing the thing, and how you can use Better Reflection in your projects to maximise your reflection-fu.
(*actual magic or time-warp not guaranteed)
ECMA5 approach to building JavaScript frameworks with Anzor BashkhazFITC
Save 10% off ANY FITC event with discount code 'slideshare'
See our upcoming events at www.fitc.ca
ECMA5 has given JavaScript a number of new ways to define and manipulate objects. In this session, attendees will learn how to combine Require.js and ECMA5’s object manipulation functions to create an inheritance model similar to class-based languages.
This session will introduce you to the new Form component in Symfony2. With the new domain-driven paradigma and its flexible design, the component opens a door to a wide range of possibilities. The brand new architecture makes creating complex forms easier and faster than ever before. This talk will teach you today what you need to know to build powerful forms tomorrow.
Building Reusable Custom Elements With AngularIlia Idakiev
What are Web Components and how we use them. What is Angular Elements and how can we package our angular components as custom elements and reuse them everywhere.
Demos: https://github.com/iliaidakiev/slides/
Sketchmine is a toolset to maintain, validate and create Sketch files. The perfect suite for design systems and design systems tooling. In this presentation, we look at challenges of large organisations and their design systems, and how we solve them with Sketchmine. Design Ops as it should be
Everything you always wanted to know about forms* *but were afraid to askAndrea Giuliano
La componente dei Form di Symfony2 rende possibile la costruzione di diverse tipologie di form in modo del tutto semplice. La sua architettura flessibile e altamente scalabile permette di poter gestire strutture adatte ad ogni tipo di esigenza. Tuttavia, conoscere come utilizzare appieno tutta la sua potenza non è banale. In questo talk verrà trattato in profondità la componente Form di Symfony2, mostrando i suoi meccanismi di base e come utilizzarli per estenderli ed introdurre la propria logica di business, così da costruire form cuciti a misura delle tue necessità.
Android Developer Group Poznań - Kotlin for Android developers
STXInsider example project in Kotlin:
https://github.com/kosiara/stx-insider
Kotlin - one of the popular programming languages built on top of Java that runs on JVM. Thanks to JetBrains support and excellent IDE integration, it’s an ideal choice for Android development. 100% Java compatibility, interoperability and no runtime overhead is just the beginning of a long list of strengths. Kotlin is supposed to be a subset of SCALA, has clear benefits for developers on one hand and keeps short compile times on the other.
As a mobile team we got interested in Kotlin a few months before its final release which gave us time to test it thoroughly before production use. The language has some clear advantages for an Android programmer - it enables migration from Java projects that have been under development for some time already. Java&Kotlin coexistence simplifies Kotlin introduction as only new functionality is written in JetBrain’s new language leaving all the legacy code untouched.
Transitioning gives the developer an opportunity to use lambdas, new syntax for data objects, extension functions to easily expand Android SDK’s classes functionality and infix notation to write DSL-like structures. Almost all the libraries you use today will work with Kotlin thanks to 100% Java compatibility. The same is true for Android SDK classes - all of them will seamlessly work with the new programming language. Kotlin gives you more choice when it comes to reflection, creating documentation and being null-pointer safe. Android works great with it out of the box so you won’t need to change your development habits.
Our production project in Kotlin turned out to be a success after 4 months of development. We had 0 bugs related to Kotlin as a programming language. Our code footprint is almost 30% smaller thanks to JetBrain’s, we benefit from nullpointer safety, closures, translated enums, data objects and use infix notation for logging and displaying Snackbars.
===========
In this presentation you'll find basic use cases, syntax, structures and patterns. Later on Kotlin is presented in Android context. Simple project structure, imports and Kotlin usage with Android SDK is explained. In the end cost of Kotlin compilation is presented and the language is compared to SCALA and SWIFT.
We look at the positive impact new syntax can have on boilerplate removal and readability improvement.
Kotlin really shines in Android development when one looks at “Enum translation”, “Extension functions”, “SAM conversions”, “Infix notation”, “Closures” and “Fluent interfaces” applied to lists. The talk, however, compares language-specifics of Java & Kotlin in terms of “Type Variance”, “Generics” and “IDE tools” as well.
In this chapter we will understand how to define custom classes and their elements. We will learn to declare fields, constructors and properties for the classes. We will revise what a method is and we will broaden our knowledge about access modifiers and methods.
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
In this session, we will present real life applications of compiler techniques helping kaChing achieve ultra confidence and power its incredible 5 minutes commit-to-production cycle [1]. We'll talk about idempotency analysis [2], dependency detection, on the fly optimisations, automatic memoization [3], type unification [4] and more! This talk is not suitable for the faint-hearted... If you want to dive deep, learn about advanced JVM topics, devoure bytecode and see first hand applications of theoretical computer science, join us.
[1] http://eng.kaching.com/2010/05/deployment-infrastructure-for.html
[2] http://en.wikipedia.org/wiki/Idempotence
[3] http://en.wikipedia.org/wiki/Memoization
[4] http://eng.kaching.com/2009/10/unifying-type-parameters-in-java.html
Defining Simple Classes
Using Own Classes and Objects
Access Modifiers
Constructors and Initializers
Defining Fields
Defining Properties, Getters and Setters
Defining Methods
Exercises: Defining and Using Own Classes
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
Games are powerful teaching tools, fostering hands-on engagement and fun. But they require careful consideration to succeed. Join me to explore factors in running and selecting games, ensuring they serve as effective teaching tools. Learn to maintain focus on learning objectives while playing, and how to measure the ROI of gaming in education. Discover strategies for pitching gaming to leadership. This session offers insights, tips, and examples for coaches, team leads, and enterprise leaders seeking to teach from simple to complex concepts.
Software Engineering, Software Consulting, Tech Lead.
Spring Boot, Spring Cloud, Spring Core, Spring JDBC, Spring Security,
Spring Transaction, Spring MVC,
Log4j, REST/SOAP WEB-SERVICES.
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
We describe the deployment and use of Globus Compute for remote computation. This content is aimed at researchers who wish to compute on remote resources using a unified programming interface, as well as system administrators who will deploy and operate Globus Compute services on their research computing infrastructure.
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaYara Milbes
Discover the transformative power of the WhatsApp API in our latest SlideShare presentation, "Top 7 Unique WhatsApp API Benefits." In today's fast-paced digital era, effective communication is crucial for both personal and professional success. Whether you're a small business looking to enhance customer interactions or an individual seeking seamless communication with loved ones, the WhatsApp API offers robust capabilities that can significantly elevate your experience.
In this presentation, we delve into the top 7 distinctive benefits of the WhatsApp API, provided by the leading WhatsApp API service provider in Saudi Arabia. Learn how to streamline customer support, automate notifications, leverage rich media messaging, run scalable marketing campaigns, integrate secure payments, synchronize with CRM systems, and ensure enhanced security and privacy.
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
Developing Distributed High-performance Computing Capabilities of an Open Sci...Globus
COVID-19 had an unprecedented impact on scientific collaboration. The pandemic and its broad response from the scientific community has forged new relationships among public health practitioners, mathematical modelers, and scientific computing specialists, while revealing critical gaps in exploiting advanced computing systems to support urgent decision making. Informed by our team’s work in applying high-performance computing in support of public health decision makers during the COVID-19 pandemic, we present how Globus technologies are enabling the development of an open science platform for robust epidemic analysis, with the goal of collaborative, secure, distributed, on-demand, and fast time-to-solution analyses to support public health.
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
JASMIN is the UK’s high-performance data analysis platform for environmental science, operated by STFC on behalf of the UK Natural Environment Research Council (NERC). In addition to its role in hosting the CEDA Archive (NERC’s long-term repository for climate, atmospheric science & Earth observation data in the UK), JASMIN provides a collaborative platform to a community of around 2,000 scientists in the UK and beyond, providing nearly 400 environmental science projects with working space, compute resources and tools to facilitate their work. High-performance data transfer into and out of JASMIN has always been a key feature, with many scientists bringing model outputs from supercomputers elsewhere in the UK, to analyse against observational or other model data in the CEDA Archive. A growing number of JASMIN users are now realising the benefits of using the Globus service to provide reliable and efficient data movement and other tasks in this and other contexts. Further use cases involve long-distance (intercontinental) transfers to and from JASMIN, and collecting results from a mobile atmospheric radar system, pushing data to JASMIN via a lightweight Globus deployment. We provide details of how Globus fits into our current infrastructure, our experience of the recent migration to GCSv5.4, and of our interest in developing use of the wider ecosystem of Globus services for the benefit of our user community.
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
Recreation management software streamlines operations by automating key tasks such as scheduling, registration, and payment processing, reducing manual workload and errors. It provides centralized management of facilities, classes, and events, ensuring efficient resource allocation and facility usage. The software offers user-friendly online portals for easy access to bookings and program information, enhancing customer experience. Real-time reporting and data analytics deliver insights into attendance and preferences, aiding in strategic decision-making. Additionally, effective communication tools keep participants and staff informed with timely updates. Overall, recreation management software enhances efficiency, improves service delivery, and boosts customer satisfaction.
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
5. Once your code compiles it usually works.2
.
2
https://wiki.haskell.org/Why_Haskell_just_works
5
6. TDD
TDD - Type driven development3
3
https://www.manning.com/books/type-driven-development-with-idris
6
7. 1. Type safe equality - ===
2. Builder pattern using Phantom type
3. Type class pattern - implicit
4. Literal type - 42.type
5. Dependent type - a.B
Type .
7
17. scalacOptions += "-Xfatal-warnings"
case class UserId(n: Int)
val john = UserId(7)
john == 7
// <console>:11: warning: comparing values of
// types UserId and Int using `=='
// will always yield false john == 7
warning -> error
17
20. Builder pa!ern
"The builder pattern is a good choice when designing
classes whose constructors or static factories would
have more than a handful of parameters."
Joshua Bloch, Effective Java
!
20
21. Builder pa!ern
"The builder pattern is a good choice when designing
classes whose constructors or static factories would
have more than a handful of parameters."
Joshua Bloch, Effective Java
!
21
33. — ADT Values : val → trait
val True = new Bool {} ➜ trait True extends Bool
33
34. — ADT Values : val → trait
val True = new Bool {} ➜ trait True extends Bool
— members : val → type X
val hasOption: Bool = True ➜ type HasOption = True
34
35. sealed trait Bool
//
val True = new Bool {}
val False = new Bool {}
val hasOption: Bool = True
//
sealed trait True extends Bool
sealed trait False extends Bool
type HasOption = True
35
51. Type class pa!ern ?
def sum[A](xs: List[A])(implicit adder: Adder[A]): A
Ad-hoc polymorphism - type parameter
implicit instance polymorphism
DI - compiler dependency injection
Spring, Guice runtime DI
51
52. implicit
!
// Adder implicit
def sum[A](xs: List[A])(implicit adder: Adder[A]): A =
xs.foldLeft(adder.zero)(adder.add)
// type class instance implicit
implicit val intAdder = new Adder[Int] {
def zero = 0
def add(x: Int, y: Int) = x + y
}
implicit val pointAdder = new Adder[Point] {
def zero = Point(0, 0)
def add(a: Point, b: Point) = Point(a.x + b.x, a.y + b.y)
}
52
60. Literal type - 42.type
? .
!
val t: 42 = 42
val x: "Jedi" = "Jedi"
60
61. Literal type - 42.type
? .
!
val t: 42 = 42
val x: "Jedi" = "Jedi"
?
61
62. Literal type - 42.type
? .
!
val t: 42 = 42
val x: "Jedi" = "Jedi"
? .
!
def f(t: Double): t.type = t
val a: 1.2 = f(1.2)
62
63. Literal type in scala
Scala http://docs.scala-lang.org/sips/pending/42.type.html
Typelevel Scala https://typelevel.org/scala/
Dotty http://dotty.epfl.ch/docs/reference/singleton-types.html
.
Literal singleton type library
.
63
64. true.type if condition
trait Cond[T] { type V ; val value: V }
implicit val condTrue = new Cond[true] { type V = String ; val value = "foo" }
implicit val condFalse = new Cond[false] { type V = Int ; val value = 23 }
def cond[T](implicit cond: Cond[T]): cond.V = cond.value
// true is type!
!
cond[true] // "foo"
// flase is type!
"
cond[false] // 23
64
66. Path Dependent type -
class A {
class B
var b: Option[B] = None
}
val a1: A = new A
val a2: A = new A
val b1: a1.B = new a1.B // a1.B .
val b2: a2.B = new a2.B // a1.B a2.B .
b1 === b2 //
66
67. Path Dependent type -
val b1: a1.B = new a1.B // a1.B .
val b2: a2.B = new a2.B // a1.B a2.B .
a1.b = Some(b1)
a2.b = Some(b1) // does not compile
Dependent Type Programming
67
74. val sort = new Key { type Value = String }
val width = new Key { type Value = Int }
74
75. val sort = new Key { type Value = String }
val width = new Key { type Value = Int }
Key Value
val hmap: HMap = HMap.empty
.add(width)(120)
.add(sort)("time")
.add(width)(true) // doesn't compile, width Int Value .
75
76. val sort = new Key { type Value = String }
val width = new Key { type Value = Int }
Key Value
val hmap: HMap = HMap.empty
.add(width)(120)
.add(sort)("time")
.add(width)(true) // doesn't compile, width Int Value .
Value .
val optionInt: Option[Int] = hmap.get(width)
val optionString: Option[String] = hmap.get(sort)
76
85. Scala in Real World.
Parallel Programming in Micro Service Architecture.5
5
http://tech.kakao.com/2017/09/02/parallel-programming-and-applicative-in-scala/
85
106. User defined type
Compiler .
case class ItemId(value: Int) extends AnyVal
case class CatalogId(value: Int) extends AnyVal
case class BrandId(value: Int) extends AnyVal
case class Status(value: Int) extends AnyVal
case class Page(value: Int) extends AnyVal
case class Size(value: Int) extends AnyVal
106
109. Page type
Int Int .
case class Page(value: Int) extends AnyVal
Page Int ? Page extends Int
Page Int .
val page: Int = Page(1) // .
109
110. shapeless .
import shapeless._
val shapely =
"Dependent type programming"
:: "Generic type programming" :: HNil
https://github.com/milessabin/shapeless
.
110
111. Tagged type
!
Phantom( ) type Compile time ( )
TypeTag @@ Phantom type
import shapeless.tag.@@
type Page = Int @@ PageTag // Page Int PageTag
val page: Page = tag[PageTag][Int](1) // ,
111
112. Tagged type
!
Phantom( ) type Compile time
TypeTag @@ Phantom type
import shapeless.tag.@@
type Page = Int @@ PageTag // Page Int PageTag
val page: Page = tag[PageTag][Int](1) // ,
// PageTag Int
page.getClass // => class java.lang.Integer
// Int .
val int : Int = page
112