Functional, Object-Oriented, and Concurrent Programming by Michel Charpentier
Author:Michel Charpentier
Language: eng
Format: epub
Publisher: Addison-Wesley Professional
Published: 2023-10-15T00:00:00+00:00
This definition is rejected by the Scala compiler because values of this Book type have no title, and therefore cannot be part of the set of publications.
As an alternative, you can define books without titles by taking them out of the Publication type. Then, of course, these books cannot be used as arguments of type Publication:
Scala
case class Book(author: String, pageCount: Int) // OK val book: Book = ... printTitle(book) // rejected by the compiler
Semantically, however, there is nothing in a programming language that forces a value of a subtype to behave like a value of the supertypeâyou can implement method title in class Book to do anything, as long as it returns a string. If a value of type S cannot meaningfully be used in code that expects a value of type T, then type S should not be a subtype of type T, and you must be careful not to introduce such a subtyping relationship inadvertently (see the aside on composition and inheritance).
The discussion of subtypes so far in this section refers to nominal subtyping: A type S is a subtype of a supertype T because the definition of S refers to T explicitlyâby name. Some programming languages use a different notion, known as structural subtyping or duck typing.9 As an illustration, you can define a type Book with all the characteristics of a publication, but which is not a subtype of type Publication:
9Named after the saying that if something looks like a duck, quacks like a duck, and walks like a duck, it is probably a duck, even if you call it something else.
Scala
case class Book(title: String, author: String, pageCount: Int)
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12528)
Hello! Python by Anthony Briggs(9875)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9763)
The Mikado Method by Ola Ellnestam Daniel Brolund(9754)
Dependency Injection in .NET by Mark Seemann(9300)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8264)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7748)
Grails in Action by Glen Smith Peter Ledbrook(7673)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7523)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6771)
Microservices with Go by Alexander Shuiskov(6540)
Practical Design Patterns for Java Developers by Miroslav Wengner(6434)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6412)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6385)
Angular Projects - Third Edition by Aristeidis Bampakos(5801)
The Art of Crafting User Stories by The Art of Crafting User Stories(5325)
NetSuite for Consultants - Second Edition by Peter Ries(5266)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5086)
Kotlin in Action by Dmitry Jemerov(5025)
