Database records and formlets and optionally populated records can be neatly all represented with the same data type when the fields are all indexed.
class Indexed i a where
type Index i (a :: *)
Basic unit type:
λ> replTy "()"
() :: ()
Basic functions:
-- λ> eval (A (L (\(C i) -> C (i * 2))) (C 2)) | |
-- 4 | |
{-# LANGUAGE GADTs #-} | |
data E a where | |
C :: a -> E a | |
L :: (E a -> E b) -> E (a -> b) | |
A :: E (a -> b) -> E a -> E b |
I'm exploring the right data types for writing a type inference with higher kinds and poly types.
Putting more things in the type system can force you to think about more things, but it also can make it harder and more verbose to write and read algorithms.
{-# LANGUAGE NamedFieldPuns #-} | |
-- The Expression Problem and my sources: | |
-- http://stackoverflow.com/questions/3596366/what-is-the-expression-problem | |
-- http://blog.ontoillogical.com/blog/2014/10/18/solving-the-expression-problem-in-clojure/ | |
-- http://eli.thegreenplace.net/2016/the-expression-problem-and-its-solutions/ | |
-- http://www.ibm.com/developerworks/library/j-clojure-protocols/ | |
-- To begin demonstrating the problem, we first need some |
output/ |
module Printf | |
%default total | |
-- Formatting AST. | |
data Format | |
= FInt Format | |
| FString Format | |
| FOther Char Format | |
| FEnd |