Giter Site home page Giter Site logo

Comments (3)

Gabriella439 avatar Gabriella439 commented on September 27, 2024

The reason for the whitespace at the beginning of the first line is for consistency once you start chaining lambdas, like this:

  λ(x : a)
→ λ(y : b)
→ λ(z : c)
→ ...

However, I could add a special case for when there is exactly one lambda, but I still personally prefer the current layout. Besides the consistency, it also makes scope more obvious. When you do this:

  λ(x : a)
→ ┌───────…                                                      
  │  e
  │
  │
  … 

... or this:

    let x = y
in  ┌───────…                                                      
    │  e
    │
    │
    … 

... the scope of the bound variable is actually bounded on the top and the left by the two syntactic components. I drew a box to show how everything within the binding's scope is confined to a rectangle

Also, records and unions will stay on a single line if they can stay within the specified column width (which is set to 80 columns in this case). Forcing every record or union to be multiple lines long seems unnecessary

Also, your version appears less readable to me, for a few reasons.

First, the closing brace in your handle definition dedents all the way to the same column as the let and in

  let handlers = { 
    Left = Natural/even, 
    Right = \(b : Bool) -> b 
  }
  in

... which makes it more difficult for me to visually scan for the matching in for a let binding since my eye expects there to be nothing but whitespace columns in between the two

Second, you brace things inconsistently. For example, your union has the opening angle bracket on the same line as the first element and the closing angle bracket on the same line as the final element:

\(union : < Left : Natural 
          | Right : Bool >

... but your record keeps the opening and closing angle brackets on separate lines from all of the fields:

  let handlers = { 
    Left = Natural/even, 
    Right = \(b : Bool) -> b 
  }

Third, you don't align syntactic elements for your unions and records. For example, your record formatting has comma and equals signs at different columns:

  let handlers = { 
    Left = Natural/even, 
    Right = \(b : Bool) -> b 
  }

... whereas if Dhall formatted a record on multiple lines due to exhausting the 80-character limit it would align all the commas and equal signs:

{ a    = 1
, aa   = 1
, aaa  = 1
, aaaa = 1
, b    = 1
, bb   = 1
, bbb  = 1
, c    = 1
, cc   = 1
, ccc  = 1
}

... which means that you can easily jump to the value of the next record field by just moving your eye one column down vertically instead of having to scan horizontally for the beginning of the next field's value

Same thing for unions: the formatter aligns the bars and the =/: symbols

I recommend trying out your formatting style on the larger example from this issue: dhall-lang/dhall-haskell#108

The current formatter produces this output on that example:

  λ ( xs
    : List
      { cores             : Natural
      , host              : Text
      , key               : Text
      , mandatoryFeatures : List Text
      , platforms         :
          List
          < AArch64_Linux  : {}
          | ARMv5tel_Linux : {}
          | ARMv7l_Linux   : {}
          | I686_Cygwin    : {}
          | I686_Linux     : {}
          | MIPS64el_Linux : {}
          | PowerPC_Linux  : {}
          | X86_64_Cygwin  : {}
          | X86_64_Darwin  : {}
          | X86_64_FreeBSD : {}
          | X86_64_Linux   : {}
          | X86_64_Solaris : {}
          >
      , speedFactor       : Natural
      , supportedFeatures : List Text
      , user              : Optional Text
      }
    )
→ List/fold
  { cores             : Natural
  , host              : Text
  , key               : Text
  , mandatoryFeatures : List Text
  , platforms         :
      List
      < AArch64_Linux  : {}
      | ARMv5tel_Linux : {}
      | ARMv7l_Linux   : {}
      | I686_Cygwin    : {}
      | I686_Linux     : {}
      | MIPS64el_Linux : {}
      | PowerPC_Linux  : {}
      | X86_64_Cygwin  : {}
      | X86_64_Darwin  : {}
      | X86_64_FreeBSD : {}
      | X86_64_Linux   : {}
      | X86_64_Solaris : {}
      >
  , speedFactor       : Natural
  , supportedFeatures : List Text
  , user              : Optional Text
  }
  xs
  Text
  (   λ ( x
        : { cores             : Natural
          , host              : Text
          , key               : Text
          , mandatoryFeatures : List Text
          , platforms         :
              List
              < AArch64_Linux  : {}
              | ARMv5tel_Linux : {}
              | ARMv7l_Linux   : {}
              | I686_Cygwin    : {}
              | I686_Linux     : {}
              | MIPS64el_Linux : {}
              | PowerPC_Linux  : {}
              | X86_64_Cygwin  : {}
              | X86_64_Darwin  : {}
              | X86_64_FreeBSD : {}
              | X86_64_Linux   : {}
              | X86_64_Solaris : {}
              >
          , speedFactor       : Natural
          , supportedFeatures : List Text
          , user              : Optional Text
          }
        )
    → λ(y : Text)
    →     (     Optional/fold
                Text
                x.user
                Text
                (λ(user : Text) → user ++ "@" ++ x.host ++ "")
                x.host
            ++  " "
            ++  ( merge
                  { Empty    = λ(_ : {}) → ""
                  , NonEmpty = λ(result : Text) → result
                  }
                  ( List/fold
                    < AArch64_Linux  : {}
                    | ARMv5tel_Linux : {}
                    | ARMv7l_Linux   : {}
                    | I686_Cygwin    : {}
                    | I686_Linux     : {}
                    | MIPS64el_Linux : {}
                    | PowerPC_Linux  : {}
                    | X86_64_Cygwin  : {}
                    | X86_64_Darwin  : {}
                    | X86_64_FreeBSD : {}
                    | X86_64_Linux   : {}
                    | X86_64_Solaris : {}
                    >
                    x.platforms
                    < Empty : {} | NonEmpty : Text >
                    (   λ ( element
                          : < AArch64_Linux  : {}
                            | ARMv5tel_Linux : {}
                            | ARMv7l_Linux   : {}
                            | I686_Cygwin    : {}
                            | I686_Linux     : {}
                            | MIPS64el_Linux : {}
                            | PowerPC_Linux  : {}
                            | X86_64_Cygwin  : {}
                            | X86_64_Darwin  : {}
                            | X86_64_FreeBSD : {}
                            | X86_64_Linux   : {}
                            | X86_64_Solaris : {}
                            >
                          )
                      → λ(status : < Empty : {} | NonEmpty : Text >)
                      → merge
                        { Empty    =
                              λ(_ : {})
                            → < NonEmpty =
                                  merge
                                  { AArch64_Linux  = λ(_ : {}) → "aarch64-linux"
                                  , ARMv5tel_Linux =
                                      λ(_ : {}) → "armv5tel-linux"
                                  , ARMv7l_Linux   = λ(_ : {}) → "armv7l-linux"
                                  , I686_Cygwin    = λ(_ : {}) → "i686-cygwin"
                                  , I686_Linux     = λ(_ : {}) → "i686-linux"
                                  , MIPS64el_Linux =
                                      λ(_ : {}) → "mips64el-linux"
                                  , PowerPC_Linux  = λ(_ : {}) → "powerpc-linux"
                                  , X86_64_Cygwin  = λ(_ : {}) → "x86_64-cygwin"
                                  , X86_64_Darwin  = λ(_ : {}) → "x86_64-darwin"
                                  , X86_64_FreeBSD =
                                      λ(_ : {}) → "x86_64-freebsd"
                                  , X86_64_Linux   = λ(_ : {}) → "x86_64-linux"
                                  , X86_64_Solaris =
                                      λ(_ : {}) → "x86_64-solaris"
                                  }
                                  element
                              | Empty    : {}
                              >
                        , NonEmpty =
                              λ(result : Text)
                            → < NonEmpty =
                                      ( merge
                                        { AArch64_Linux  =
                                            λ(_ : {}) → "aarch64-linux"
                                        , ARMv5tel_Linux =
                                            λ(_ : {}) → "armv5tel-linux"
                                        , ARMv7l_Linux   =
                                            λ(_ : {}) → "armv7l-linux"
                                        , I686_Cygwin    =
                                            λ(_ : {}) → "i686-cygwin"
                                        , I686_Linux     =
                                            λ(_ : {}) → "i686-linux"
                                        , MIPS64el_Linux =
                                            λ(_ : {}) → "mips64el-linux"
                                        , PowerPC_Linux  =
                                            λ(_ : {}) → "powerpc-linux"
                                        , X86_64_Cygwin  =
                                            λ(_ : {}) → "x86_64-cygwin"
                                        , X86_64_Darwin  =
                                            λ(_ : {}) → "x86_64-darwin"
                                        , X86_64_FreeBSD =
                                            λ(_ : {}) → "x86_64-freebsd"
                                        , X86_64_Linux   =
                                            λ(_ : {}) → "x86_64-linux"
                                        , X86_64_Solaris =
                                            λ(_ : {}) → "x86_64-solaris"
                                        }
                                        element
                                      )
                                  ++  ","
                                  ++  result
                              | Empty    : {}
                              >
                        }
                        status
                        : < Empty : {} | NonEmpty : Text >
                    )
                    < Empty = {=} | NonEmpty : Text >
                  )
                  : Text
                )
            ++  " "
            ++  x.key
            ++  " "
            ++  Integer/show (Natural/toInteger x.cores)
            ++  " "
            ++  Integer/show (Natural/toInteger x.speedFactor)
            ++  " "
            ++  ( merge
                  { Empty    = λ(_ : {}) → ""
                  , NonEmpty = λ(result : Text) → result
                  }
                  ( List/fold
                    Text
                    x.supportedFeatures
                    < Empty : {} | NonEmpty : Text >
                    (   λ(element : Text)
                      → λ(status : < Empty : {} | NonEmpty : Text >)
                      → merge
                        { Empty    =
                            λ(_ : {}) → < NonEmpty = element | Empty : {} >
                        , NonEmpty =
                              λ(result : Text)
                            → < NonEmpty = element ++ "," ++ result
                              | Empty    : {}
                              >
                        }
                        status
                        : < Empty : {} | NonEmpty : Text >
                    )
                    < Empty = {=} | NonEmpty : Text >
                  )
                  : Text
                )
            ++  " "
            ++  ( merge
                  { Empty    = λ(_ : {}) → ""
                  , NonEmpty = λ(result : Text) → result
                  }
                  ( List/fold
                    Text
                    x.mandatoryFeatures
                    < Empty : {} | NonEmpty : Text >
                    (   λ(element : Text)
                      → λ(status : < Empty : {} | NonEmpty : Text >)
                      → merge
                        { Empty    =
                            λ(_ : {}) → < NonEmpty = element | Empty : {} >
                        , NonEmpty =
                              λ(result : Text)
                            → < NonEmpty = element ++ "," ++ result
                              | Empty    : {}
                              >
                        }
                        status
                        : < Empty : {} | NonEmpty : Text >
                    )
                    < Empty = {=} | NonEmpty : Text >
                  )
                  : Text
                )
            ++  "\n"
          )
      ++  y
  )
  ""

from dhall-lang.

psibi avatar psibi commented on September 27, 2024

That's reasonable and convincing!

The reason I opened the was I was improving the indendation in the emacs mode I was working on and starting your configuration by leaving spaces is not natural. It seems I would just let the formatter take care of it, then. Thanks!

from dhall-lang.

Gabriella439 avatar Gabriella439 commented on September 27, 2024

You're welcome!

from dhall-lang.

Related Issues (20)

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.