Skip to content

Support dynamic and static printing

it's pretty clear that the way we print currently isn't all that pretty.

While it makes sense to break on long lines, it's also not the only way to pretty print. We can also layout everything statically (with the same rules at all times). Static layout rules mean that printing becomes more consistent and predictable. Static layout rules also mean that even stuff that could fit on one line might be broken up into multiple lines. Depends on the layout rules.

Copying text of issues for posterity

From

  • https://github.com/joneshf/purty/issues/3

    class 
      ( Patch ad
      ) <=
      Diff a d | a -> d where
        diff ::
          a ->
          a ->
          d
  • https://github.com/joneshf/purty/issues/4

    map ::
      forall a b da db.
      Patch ada =>
      Patch bdb =>
      (Jet a -> Jet b) ->
      Jet (IArray a) ->
      Jet (IArray b)
    map f { position: IArray xs, velocity: dxs } = let go (InsertAt i a) = Just (InsertAt i (f (constant a))."position")
                                                      go (DeleteAt i) = Just (DeleteAt i)
                                                      go (ModifyAt i da) = (xs !! i) <#> \a ->
                                                          let j = f { "position": a
                                                                    , "velocity": toChange da
                                                                    }
    
                                                          in ModifyAt i (fromChange j."velocity")
    
                                                  in { "position": IArray (Prelude.map (_."position" <<< f <<< constant) xs)
                                                      , "velocity": toChange (mapMaybe go (fromChange dxs))
                                                      }
  • https://github.com/joneshf/purty/issues/6

    From

    module Main where
    
    import Prelude
    import Control.Monad.Eff.Console
    
    type T = { foo :: Int, bar :: { baz :: Int, qux :: { lhs :: Int, rhs :: Int } } }
    
    init :: T
    init = { foo: 1, bar: { baz: 2, qux: { lhs: 3, rhs: 4 } } }
    
    updated :: T
    updated = init { foo = 10, bar { baz = 20, qux { lhs = 30, rhs = 40 } } }
    
    expected :: T
    expected = { foo: 10, bar: { baz: 20, qux: { lhs: 30, rhs: 40 } } }
    
    check l r =
      l.foo == r.foo &&
      l.bar.baz == r.bar.baz &&
      l.bar.qux.lhs == r.bar.qux.lhs &&
      l.bar.qux.rhs == r.bar.qux.rhs
    
    main = do
      when (check updated expected) $ log "Done"

    to

    module Main where
    
    import Prelude 
    import Control.Monad.Eff.Console 
    
    type T
      = {"foo" :: Int, "bar" :: {"baz" :: Int, "qux" :: {"lhs" :: Int, "rhs" :: Int}}}
    init ::
      T
    init = { "foo": 1
          , "bar": { "baz": 2
                    , "qux": {"lhs": 3, "rhs": 4}
                    }
          }
    
    updated ::
      T
    updated = init { "foo" = 10
                  , "bar" { "baz" = 20
                          , "qux" {"lhs" = 30, "rhs" = 40}
                          }
                  }
    
    expected ::
      T
    expected = { "foo": 10
              , "bar": { "baz": 20
                        , "qux": {"lhs": 30, "rhs": 40}
                        }
              }
    
    check l r = l."foo" == r."foo" && l."bar"."baz" == r."bar"."baz" && l."bar"."qux"."lhs" == r."bar"."qux"."lhs" && l."bar"."qux"."rhs" == r."bar"."qux"."rhs"
    
    main = do
        when (check updated expected) $ log "Done"
Edited by Hardy Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information