
As you notice, the show functions for collections are implemented wrongly, they should print Fully.Qualified.Module.fromList [(key,value),...] High time to repent now and not sin again. Positive example: https://hackage.haskell.org/package/Agda-2.4.0/docs/src/Agda-Utils-BiMap.htm... On 29.10.2014 23:07, Christopher Done wrote:
Well, I think |fromList [(1, 'a')]| is kind of unhelpful:
1. It almost never is a straight copy/paste, you will have to go and add M. to the fromList. 2. It doesn’t actually tell you what you’re looking at:
|(fromList [(0,'a'),(1,'b'),(2,'c'),(3,'d'),(4,'e'),(5,'f')] ,fromList [(0,'a'),(1,'b'),(2,'c'),(3,'d'),(4,'e'),(5,'f')] ,fromList [1,2,3,4,5] ,fromList [1,2,3,4,5]) |
What are you looking at?
Answer:
|>import qualified Data.Mapas M
import qualified Data.HashMap.Strictas HM import qualified Data.Vectoras V import qualified Data.Vectoras S (M.fromList (zip [0..5] ['a'..]) ,HM.fromList (zip [0..5] ['a'..]) ,S.fromList [1..5] ,V.fromList [1..5]) |
It’s true that numbers (|Int|/|Integer|) get a free pass on this, but I consider those an exception. I’d prefer (if we’re restricting ourselves to strings) something like
|Map [(0,'a'),(1,'b'),(2,'c')] StrictHashMap [(0,'a'),(1,'b'),(2,'c')] Set [0,1,2,3,4,5] Vector [0,1,2,3,4,5] |
But this is not the status quo and I don’t see it changing soon. People are set on the “looks like code” idea more than “describe the data structure”.
------------------------------------------------------------------------
Digression:
While we’re on the subject, I’d like to be able to convert any Haskell value to a Presentation http://hackage.haskell.org/package/present-1.1/docs/Present-Types.html which IDEs and browsers can use to trivially expand data structures lazily, like this:
|λ> present (fromJust (fromList [0])) [1..5] Just (List "[Integer]" [("Integer",@0→0),("[Integer]",@0→1)]) λ> present (fromJust (fromList [0,0])) (T.pack"hi") Just (Char "Char" "'h'") λ> present (fromJust (fromList [0,1])) (T.pack"hi") Just (String "Text" [("Char",@0→1→0),("Text",@0→1→1)]) λ> present (fromJust (fromList [0]))"hello!" Just (String "String" [("Char",@0→0),("String",@0→1)]) λ> present (fromJust (fromList [0,0]))"hello!" Just (Char "Char" "'h'") λ> present (fromJust (fromList [0,1,0]))"hello!" Just (Char "Char" "'e'") |
Video of Emacs taking advantage of this output. https://www.youtube.com/watch?v=oJhIvHtflbI
And to be able to choose /how to present/ the structure. E.g. if I wanted, I could present a |Set| like:
|{0 1 2 3 4 5} |
and a |Map| like:
|{0 => 'a',1 => 'b',2 => 'c' } |
and, let’s say I add a |Tree| constructor to the |Presentation| type, i.e. a known “tree-ish” structure, then I can render a |Data.Tree| like:
| {0 1 2 3} / \ {4 5 6} {7 8 9} … … |
Where the |…| is an expansion thing to click. Because |Presentation| contains type information, you can hover your mouse or whatever to inspect the types of things.
But making this work in the general sense has been hard: Show is not parseable, many data types in real projects are not instances of Data (and types like Text and Vector have bogus instances). I believe my only recourse will be using the GHC API to inspect data types or template-haskell’s |reify| in an effort to cross module encapsulation. Now that Typeable is not user-definable, one cannot use the derive http://hackage.haskell.org/package/derive package, either. I think the |:sprint|/|:print| of GHCi is sort of there, but using it would be more hacky — it would be better to hook into whatever API is used to produce that feature in GHC and spit out a |Presentation|.
In general, it seems the current Haskell state of affairs makes it tricky to just print a value and expand it incrementally in the same way that you can in Common Lisp or JavaScript.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Andreas Abel <>< Du bist der geliebte Mensch. Department of Computer Science and Engineering Chalmers and Gothenburg University, Sweden andreas.abel@gu.se http://www2.tcs.ifi.lmu.de/~abel/