Comments (2)
With the proposed design, there is no way to have multiple Validatable a
instances for type a
with different raw
inputs.
So, this is my new suggestion:
newtype Username = Username { un :: Text }
instance Validatable A Username where
type Parsed Username = Username
type Errors Username = AValidationErrors
validate :: A -> Sem '[] (Validation ValidationErrors Username)
validate = undefined
instance Validatable B Username where
type Parsed Username = Username
type Errors Username = BValidationErrors
validate :: B -> Sem '[] (Validation ValidationErrors Username)
validate = undefined
And for Form v
:
data Form (v :: Validity) = Form
{ usernameA :: Validate v A Username
, usernameB :: Validate v B Username
}
deriving stock Generic
-- Because the Validatable is a multi-param typeclass we should use standalone deriving
deriving via (Generically (Form v)) instance Validatable (Form 'Raw) (From 'Parsed)
from cascade.
There was an issue with safe coercion through Sem r a
type from polysemy.
Both type variables of Sem r a
are nominal which causes Sem r (Generically a)
not to be coercible with Sem r a
.
So here is the deal!
I made a type family called Parsed
which deconstruct Generically
type:
type family Parsed (a :: Type) :: Type where
Parsed (Generically a) = a
Parsed a = a
Then the Validatable.validate
function type signature would become:
validate :: raw -> Sem (Effects raw parsed) (Validation (Errors raw parsed) (Parsed parsed))
By now we are able to derive Validatable
typeclass via Generically
but due to usage of Parsed parsed
in the return type of validate
compiler needs disambiguation.
f :: Form 'Raw -> Sem '[] (Validation (Errors (Form 'Raw) (From 'Parsed)) (Form 'Parsed))
f = validate -- Ambiguous parsed0
To solve ambiguity, I renamed the Validatable.validate
function to Validatable.parse
and introduced another function with the following constraints:
validate :: forall raw parsed
. Validatable raw parsed
=> parsed ~ Parsed parsed
=> raw
-> Sem
(Effects raw parsed)
(Validation (Errors raw parsed) parsed)
validate = parse @raw @parsed
from cascade.
Related Issues (13)
- Obtain PostgreSQL connection information through command line arguments
- Obtain PostgreSQL connection information from environment variables
- CLI version information
- Obtain HTTP port for starting API HTTP server via command line arguments
- Obtain HTTP port for starting HTTP API server from environment variables
- Making integration tests runnable on Linux HOT 1
- Authorization
- Newtype deriving strategy for Show
- Add ON UPDATE CASCADE to foregin keys in migrations for more safety
- User and authentication endpoints
- Logging
- Tasks endpoints
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cascade.