FormationAI / dhall-bhat

Tasty meal of Dhall
66 stars 11 forks source link

Add Bifunctors #33

Closed basile-henry closed 6 years ago

basile-henry commented 6 years ago

This PR implements Issue #25 by adding:

Here is an example:

➜ dhall <<EOF
    let Either = ./Either/Type
in  let bifunctor = ./Either/Bifunctor
in  let first = ./Bifunctor/first Either bifunctor Natural Bool Text
in
    first
      (\(x : Natural) -> Natural/even x)
      < Left = 4 | Right : Text >
EOF
< Left : Bool | Right : Text >

< Left = True | Right : Text >

The order of the type arguments for bimap follow the naming used in Haskell's bimap as opposed to using the one used in the mapBoth definition. If this is an issue, I'd be more than happy to change that. :smile:

basile-henry commented 6 years ago

@FintanH I mainly followed the code structure from Functor, it does look nicer as you suggested though :+1:

Did I understand correctly that the new structure for package.dhall is just a lambda returning the record like for Applicative?

Is package.dhall something that is often used in Dhall projects? I don't have much experience using Dhall myself, just very interested in its development, is there any code structure most Dhall project adhere to?

sellout commented 6 years ago

Good spot with Functor/package.dhall – we should trim that down. Must have gotten overlooked before.

And yeah, package.dhall is a convention from @Gabriel439 that exposes a directory as a single record. In dhall-bhat, that often provides a single place to specify common type parameters for the operations.