Coder Social home page Coder Social logo

registry's Introduction

Registry Hackage Build Status

Join the chat at https://gitter.im/etorreborre/registry

It's functions all the way down

Presentation

This library provides a data structure, a "Registry", to control the creation of functions from other functions. You can use this technique to:

You can watch a video presenting the main ideas behind the library here.

The following sections introduce in more details the problem that this library is addressing, the concepts behind the solution and various use-cases which can arise on real projects:

  1. what is the problem?
  2. the concept of a Registry and the resolution algorithm
  3. how does this compare to monad transformers and effects?

Tutorials

  1. tutorial: use a Registry to create applications and define components
  2. use a Registry to compose Hedgehog generators
  3. workshop: implement your own simplified registry and understand the basic concepts behind it

How-tos

  1. how to install this library?
  2. how to do mocking?
  3. how to specialize some values in some contexts?
  4. how to control effects occurring when creating a component (like a connection pool)?
  5. how to allocate resources which must be finalized?
  6. how to extract a dot graph from the registry in an application?
  7. how to interact with a library using monad transformers?
  8. how to remove boilerplate due to parameter passing?
  9. how to create a typeclass from a record of functions?
  10. how to read type errors?

Reference guides

  1. main operators and functions
  2. implementation notes

registry's People

Contributors

andrevdm avatar etorreborre avatar gitter-badger avatar mijicd avatar sanjivsahayamrea avatar symbiont-eric-torreborre avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

registry's Issues

is makeSafe missing an (out :- a) constraint?

Should

makeSafe :: forall a ins out. (Typeable a, Solvable ins out) => Registry ins out -> a

be

makeSafe :: forall a ins out. (Typeable a, Solvable ins out, out :- a) => Registry ins out -> a

?

Because as it stands I can compile and run makeSafe @a @'[] @'[] which bombs out at runtime and that doesn't feel very safe.

outTo behaviour

I'm not sure if this is a bug but the docs say that outTo converts i1 -> i2 -> ... -> n o to m i1 -> m i2 -> ... -> m o using a natural transformation forall a. n a -> m a.

From my testing outTo seems to instead convert i1 -> i2 -> ... -> n o to i1 -> i2 -> ... -> m o

Here is an example

{-# LANGUAGE RecordWildCards #-}
module RegistryExample where

import Data.Registry
import Control.Monad.IO.Class (liftIO)

data A = A {a :: Int} deriving Show
makeA :: A
makeA =  A 1

data B = B {b :: Int} deriving Show
makeB :: RIO B
makeB = pure $ B 2

data C = C {ca :: A, cb :: B, c :: Int} deriving Show
makeC :: A -> B -> IO C
makeC a b = pure $ C a b 3

registry =
     fun (outTo @RIO liftIO makeC)
  +: fun makeB
  +: funTo @RIO makeA
  +: end

doSomethingWithC :: Result -> C -> IO ()
doSomethingWithC _ C{..} = print (ca, cb, c)

main :: IO ()
main = withRegistry registry $ doSomethingWithC

This gives me compile errors

/home/jon/projects/haskell/fin/src/RegistryExample.hs:30:8: error:
    • No element of type A can be built out of the registry
    • In the expression: withRegistry registry
      In the expression: withRegistry registry $ doSomethingWithC
      In an equation for ‘main’:
          main = withRegistry registry $ doSomethingWithC
   |
30 | main = withRegistry registry $ doSomethingWithC
   |        ^^^^^^^^^^^^^^^^^^^^^

/home/jon/projects/haskell/fin/src/RegistryExample.hs:30:8: error:
    • No element of type B can be built out of the registry
    • In the expression: withRegistry registry
      In the expression: withRegistry registry $ doSomethingWithC
      In an equation for ‘main’:
          main = withRegistry registry $ doSomethingWithC
   |
30 | main = withRegistry registry $ doSomethingWithC
   |        ^^^^^^^^^^^^^^^^^^^^^

However if I write

registry =
     fun (argsTo @RIO (outTo @RIO liftIO makeC))
  +: fun makeB
  +: funTo @RIO makeA
  +: end

it compiles and seems to work fine, which is why I think outTo is not lifting the arguments.

allTo works inconsistently

I noticed that the argsTo function is gone and its functionality is supposed to be subsumed by allTo but somehow whether expressions are inline or not affects it.

a :: Int -> Int -> IO Int 
a = undefined
b = outTo @RIO liftIO a
c = allTo @RIO b
d = allTo @RIO (outTo @RIO liftIO a)

2020-08-17-151857_596x89_escrotum
I expect d to be the same as c but it's not.

Also, as a side question, I've been doing the above using argsTo in the past to lift IO actions into RIO so I don't have to return RIO in my module creation functions unless necessary. Is that the right way of doing it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.