일 뿐이다. 유령 타입의 주 기능은 ‘표식’ 역할이다. 실제로는 그 타입의 인스턴스를 전혀 사용하
지 않는다.
지금 설명하려는 유령 타입의 사용법은 사실 암시와는 아무 관계가 없다. 하지만 우리가 해결하
려는 설계 문제를 논할 때는 딱 들어맞는다.
유령 타입은 특정 순서로 진행해야 하는 작업 흐름을 정의할 때 아주 유용하다. 예를 들어 단순
화한 급여 계산 프로그램을 생각해보자. 미국 세법에 따르면, 세금을 계산하기 전에 급여에서 보
험료와 특정 요건을 갖춘 저축(
401k
) 계정
1
에 대한 기여분을 공제해야 한다. 따라서 급여 계산
프로그램은 반드시 이런 ‘세전
pre
-
tax
’ 공제를 먼저 수행하고, 그 후 세금을 공제하고, 그 후 가능
한 세후 공제를 계산해서 지불 가능한 순 급여를 결정해야 한다.
다음은 한 가지 가능한 구현 방법을 보여준다.
//
src
/
main
/
scala
/
progscala2
/
implicits
/
phantom
-
types
.
scala
//
급여
계산을
위한
작업
흐름
package progscala
.
implicits
.
payroll
sealed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.
O’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
I wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
I’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
I'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.