Symptom: A weird error such as:
error FS0001: This expression was expected to have type
'FSI_0011.MyType'
but here has type
'FSI_0012.MyType'
"What is a functional approach to logging and transactions" is a question I get asked sometimes. So here's my take.
First, there is never a perfect answer! It depends on your tolerance for impurity, what's compatible with the rest of the code and what other maintainers expect.
I use F#, which generally has a pragmatic approach to this kind of thing.
In Haskell or purist FP Scala (e.g. with Cats/Scalaz) the standard approach would be to use a writer monad, but for F#/OCaml/ReasonML etc, that would probably be overkill.
Some recommended books for improving as a software developer
Most software books are too language specific and go out of date too quickly. What I find has stayed with me are books about bigger concepts, such as systems thinking and complexity, and also so-called "soft skills" such as management and psychology.
These are all really about developing empathy for other people :)
(* | |
Demonstrates DTO validation for a news feed domain | |
*) | |
// "result.fsx" comes from https://github.com/swlaschin/DmmfWorkshop/blob/master/src/E-ModelingErrors/Result.fsx | |
#load "result.fsx" | |
module Domain = | |
type DocumentId = DocumentId of int | |
type EmailAddress = EmailAddress of string |
module Util = | |
/// Merge a new list into an old list. | |
/// The sortKey is used to sort and compare the keys. | |
/// The insert/update/delete actions are called as appropriate. They return Options so that | |
/// you can filter at the same time. | |
let merge oldList newList sortKey insertAction updateAction deleteAction = | |
let rec innerMerge oldList newList = | |
match oldList,newList with |
I suggest that you create one or more Api.fs
files to expose F# code in a C# friendly way.
In this file:
PascalCase
names. They will appear to C# as static methods.See also https://fsharpforfunandprofit.com/posts/list-module-functions/
// ------------------------------
// add 1 to each item
// ------------------------------