Skip to content

Instantly share code, notes, and snippets.

@ChrisDobby
Created August 28, 2015 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisDobby/5854e2faceab3e92b9be to your computer and use it in GitHub Desktop.
Save ChrisDobby/5854e2faceab3e92b9be to your computer and use it in GitHub Desktop.
Visitor in F#
namespace Visitor
type IPrescription =
abstract member Accept : IPrescriptionVisitor -> unit
and IPrescriptionVisitor =
abstract member Visit : PointInTime -> unit
abstract member Visit : Infusion -> unit
and PointInTime() =
interface IPrescription with
member this.Accept visitor = visitor.Visit this
and Infusion() =
interface IPrescription with
member this.Accept visitor = visitor.Visit this
type PrescriptionLabelVisitor() =
interface IPrescriptionVisitor with
member this.Visit (prescription : PointInTime) = printf "********** Label for point in time dose\n\n"
member this.Visit (prescription : Infusion) = printf "********** Label for infusion\n\n"
type PrescriptionPrintoutVisitor() =
interface IPrescriptionVisitor with
member this.Visit (prescription: PointInTime) = printf "********** Printout for point in time dose\n\n"
member this.Visit (prescription: Infusion) = printf "********** Printout for infusion\n\n"
type PrescriptionCsvVisitor() =
interface IPrescriptionVisitor with
member this.Visit (prescription: PointInTime) = printf "********** Csv for point in time dose\n\n"
member this.Visit (prescription: Infusion) = printf "********** Csv for infusion\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment