@@ -1,7 +1,9 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Elm.Compiler.Type
3module Elm.Compiler.Type
4− ( Type(..), toString
6+ , toString
5 , Program(..)
7 , Program(..)
@@ -49,12 +51,23 @@ data Program =
49-- TO STRING
51-- TO STRING
52−data Context = None | ADT | Function
54+data Format = OneLine | MultiLine
55−toString :: Type -> String
57+toString :: Format -> Type -> String
56−toString tipe =
58+toString format tipe =
57− P.render (toDoc None tipe)
67+ P.renderStyle (P.Style mode 80 1.0) (toDoc None tipe)
70+data Context = None | InType | InFunction
60toDoc :: Context -> Type -> P.Doc
73toDoc :: Context -> Type -> P.Doc
@@ -62,7 +75,7 @@ toDoc context tipe =
62 case tipe of
75 case tipe of
63 Lambda _ _ ->
76 Lambda _ _ ->
64 let t:ts =
77 let t:ts =
65− map (toDoc Function) (collectLambdas tipe)
78+ map (toDoc InFunction) (collectLambdas tipe)
68 P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
81 P.sep [ t, P.sep (map (P.text "->" <+>) ts) ]
@@ -89,15 +102,18 @@ toDoc context tipe =
92− application =
105+ application =
94− (P.text (Text.unpack name))
107+ (P.text (Text.unpack name))
96− (P.sep $ map (toDoc ADT) args)
109+ (P.sep $ map (toDoc InType) args)
98− case (context, args) of
111+ case (context, args) of
99− (ADT, _ : _) -> P.parens application
113+ P.parens application
100− _ -> application
116+ application
102 App _ _ ->
118 App _ _ ->
@@ -160,7 +176,7 @@ flattenRecord tipe =
161encode :: Type -> Encode.Value
177encode :: Type -> Encode.Value
162encode tipe =
178encode tipe =
163− Encode.text (Text.unwords (Text.words (Text.pack (toString tipe))))
179+ Encode.text (Text.pack (toString OneLine tipe))
166decoder :: Decode.Decoder Type
182decoder :: Decode.Decoder Type