-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbond.txt
More file actions
2043 lines (1636 loc) · 67.4 KB
/
bond.txt
File metadata and controls
2043 lines (1636 loc) · 67.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
3/25/2018
Tried for a long time to get to a point of confidence with
generators within properties in QuickCheck (in the WordNumber
module of the addition project) but I can't get past various
type errors.
What I can get working:
Inventing a round-trip for WordNumber so that I can
have a property to test with QuickCheck. I felt proud
of making that happen.
main = quickCheck ...
main = verboseCheck ...
prop_numberWordNumber :: Property
prop_numberWordNumber =
forAll zeroThroughNineDigit
(\c -> (numberWord $ wordNumber c) == c)
prop_wordNumberWord :: Property
prop_wordNumberWord =
forAll zeroThroughNineWord
(\w -> (wordNumber $ numberWord w) == w)
The two problems with these are:
1. They run 100 tests but there aren't that many inputs even
2. One digit or one word-number tests might be better focused on the
helpers rather than the main wrapper functions wordNumber
and numberWord
The main thing I can't get working is:
With numbers that are NonNegative (there seems to be a helper
for this in the QuickCheck library) generate a lot of tests
that we can use the round-trip property to validate.
The main issue is generating the non-negative data.
3/24/2018
Have had a hard time lately: I've recently learned
that it's possible to run Haskell not only in Azure Functions
but also Azure Paas V1 *and* Paas V2 with zip deployment.
Not only is this a huge deal since those are the vernacular
systems I work with at work, but I alredy know how to automate
the compliant deployment of Azure Functions with Zip deployment
so Haskell suddenly seems so close and yet I have so much to
work through in the Haskell Book.
In that context I am working through Chapter 14 which poses the
following humbling challenge: go back to chapter 8 and implement:
digits :: Int -> [Int]
where the input is a number and the output is simply a list
of those numbers individually like:
> digits 542
> [5, 4, 2]
For some reason, when I do this the numbers come out in the
wrong order. But rather than trivially regarding this as a bug
I began wondering how this could even be a thing since a) my
code is so simple and b) by this time I know how to Haskell.
Right? Right??? So at this point rather than translating the
new feeling of closeness of Haskell in the shop toward a push
to drive through the Haskell Book I have this haunting over-
thinking thing going on about whether I am really learning
this stuff.
What needs to happen:
- Shut up and drain digits :: Int -> [Int] of issues to the
point I understand it
- Know that I am still learning
- Know that I am getting there
- Know that I have plenty to fallback on even if we can't
do Haskell right this minute at work, I *am* closer than
ever
Haskelly on Windows never would show tooltips. It would get
stuck at a tooltip saying "Loading...". Haskelly seems to work
on OS X just fine. To get tooltips I endedup installing the
Haskero extension which also added a number of interesting and
valuable warnings in the Problems output and successfully
shows tooltips which is great.
lol, but by uninstalling Haskelly lost ctrl-shift-P stack ghci
can hack this back by starting terminal in code and just running
stack ghci foo.hs
*WordNumber> reverse $ (542 `mod` 10) : ((542 `quot` 10) `mod` 10) : (((542 `quot` 10) `quot` 10) `mod` 10) : []
[5,4,2]
Also, at the end of the day any speedbump like this is a learning
lesson which is the whole reason we got into this game.
3/23/2018
successfully got tooltips with actual type information to appear in Haskell
code (on os x) doing this:
1. install haskelly vs code extension
2. stack install intero QuickCheck stack-run
3. stack build intero QuickCheck stack-run
Then mousing over a symbol (ex. Just) will show the type in a tooltip!
got ghci working by installing ghci helper by Richard Cook
doesn't create 'stack ghci' command but rather 'start ghci using stack'
which literally just starts ghci, nothing else, have to load an
actual *.hs file rather than 'stack ghci' which takes the current
file into context
2/5/2017
stack ghci --ghci-options -XNoImplicitPrelude
1/26/2018
git rev-list --count 6d2ddd053511a..HEAD
1/10/2018
I'm digging how comfortable I am knowing functions and using
operators like $ and . casually in the repl. Super neat.
ex. rangeOk $ map ord message
All that comes from VigenereCipherChapter11.hs
1/9/2018
Can we use CipherChapter9.hs as a module and
purely recycle that code?
the idea is to keep the Vigenere stuff in that
file and the caesar stuff over there.
Nope, can't do that: caesar assumes we pass it
a whole string that is uniformly shifted by
an index where Vigenere has a unique shift per
index. So Vigenere is one level more complex
thank the caesar cipher.
1/6/2018
*LogicGoats> :set +t
*LogicGoats> 3
3
it :: Num t => t
*LogicGoats> :set -XFlexibleInstances
*LogicGoats> :showi language
base language is: Haskell2010
with the following modifiers:
-XNoDatatypeContexts
-XExtendedDefaultRules
-XFlexibleInstances
-XNoMonomorphismRestriction
-XNondecreasingIndentation
-XTypeSynonymInstances
1/5/2018
How does this make sense:
*DogTypes> :t HuskyData
HuskyData :: HuskyType a
*DogTypes> :t HuskyData :: HuskyType String
HuskyData :: HuskyType String :: HuskyType String
Was expecting:
*DogTypes> :t HuskyData :: HuskyType String
HuskyData :: HuskyType String
fails:
*DogTypes> :t DogueDeBordeaux String :: DogueDeBordeaux String
<interactive>:1:17: error:
Data constructor not in scope: String :: String
works:
DogueDeBordeaux "foo" :: DogueDeBordeaux String
:: DogueDeBordeaux String
data Doggies a =
Husky a
| Mastiff a
deriving (Eq, Show)
*DogTypes> :k Doggies
Doggies :: * -> *
*DogTypes> :k Doggies Int
Doggies Int :: *
also:
I had thought that the data ctor couldn't mention a type
where the type ctor hadn't already mentioned it but that's
not the case. So this fails simply because there's no a
in any scope, not just type ctor scope:
data Foo = Bar a
and this use of a type on the data ctor side works because
there is an Int in scope:
data Foo = Bar Int
does this work?
data Foo = Num a => Bar a
-- no, a still not in scope
-- but I wonder if you can still require typeclass instances
This also does not work:
data Foo a = Num a => Bar a
<interactive>:82:14: error:
* Data constructor `Bar' has existential type variables, a context, or a specialised result type
Bar :: forall a. Num a => a -> Foo a
(Use ExistentialQuantification or GADTs to allow this)
* In the definition of data constructor `Bar'
In the data type declaration for `Foo'
And this also doesn't work out of the box:
data Num a => Foo a = Bar a
<interactive>:83:6: error:
Illegal datatype context (use DatatypeContexts): Num a =>
12/15/2017
Observe:
Prelude> c 3 $ c 4 $ c 5 $ c 6 7
3
The idea here is:
3 + 4 + 5 + 6
as opposed to
3 * 4 + 5 * 6 where the different operators (+) and (*) are competing for precedence.
Furthermore, the idea is that, if we're in a foldr situation, and we evaluate from the
left side because all the precedences are the same between all the functions since all
the functions are const, then when we go to do this, the output is 1:
xs = [1..5] ++ undefined
foldr const 0 xs
which *incorrectly* written out looks like:
(const 1 (const 2 (const 3 (const 4 (const 5 (const ..? 0))))))
If you wrote it out this way, and I have many times, you'd assume the result would be:
const ..? 0 which is exception
but if we instead look at it like
const :: a -> b -> a
const x _ = x
and:
const 1 _
Then the answer should be 1.
12/14/2017
Prelude> let xs = [1..3] ++ undefined
Prelude> (const 1 (const 2 (const 3 (const undefined 0))))
1
Prelude> xs
[1,2,3*** Exception: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries\base\GHC\Err.hs:79:14 in base:GHC.Err
undefined, called at <interactive>:1:20 in interactive:Ghci1
Prelude> (const 1 (const 2 (const 3 0)))
1
Prelude> foldr const 0 xs
1
Prelude> (const 1 (const 2 (const 3 (const undefined 0))))
1
Prelude> (const 1 (const 2 (const 3 (const 5 0))))
1
Prelude> const 1 undefined
1
Prelude> const undefined 1
*** Exception: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries\base\GHC\Err.hs:79:14 in base:GHC.Err
undefined, called at <interactive>:11:7 in interactive:Ghci8
Prelude> (const 1 (const undefined 3))
1
Prelude> (const 1 (const undefined undefined))
1
Prelude> 2^2^3
256
Prelude> 2^(2^3)
256
Prelude> (2^2)^3
64
Prelude> const 1 (const undefined undefined)
1
Prelude> :i const
const :: a -> b -> a -- Defined in `GHC.Base'
Prelude> fc = flip const
Prelude> fc undefined 1
1
Prelude> (fc 1 (fc 2 (fc 3 4)))
4
Prelude> (fc 1 (fc 2 (fc 3 undefined)))
*** Exception: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries\base\GHC\Err.hs:79:14 in base:GHC.Err
undefined, called at <interactive>:25:19 in interactive:Ghci17
Prelude> (fc undefined (fc 2 (fc 3 4)))
4
Prelude>
12/4/2017
http://www.stephendiehl.com/posts/haskell_2018.html
https://futtetennismo.me/posts/docker/2017-11-24-docker-haskell-executables.html
12/2/2017
Haskell PDBs: https://ghc.haskell.org/trac/ghc/ticket/12397
11/30/2017
Prelude> mySqr = [x^2 | x <- [1..10]]
Prelude> mySqr
[1,4,9,16,25,36,49,64,81,100]
Prelude> [x | x <- mySqr, rem x 2 == 0]
[4,16,36,64,100]
Prelude> [(x,y) | x <- mySqr, y <- mySqr, x < 50, y > 50]
[(1,64),(1,81),(1,100),(4,64),(4,81),(4,100),(9,64),(9,81),(9,100),(16,64),(16,81),(16,100),(25,64),(25,81),(25,100),(36,64),(36,81),(36,100),(49,64),(49,81),(49,100)]
Prelude> take 5 [(x,y) | x <- mySqr, y <- mySqr, x < 50, y > 50]
[(1,64),(1,81),(1,100),(4,64),(4,81)]
Prelude> :i elem
class Foldable (t :: * -> *) where
...
elem :: Eq a => a -> t a -> Bool
...
-- Defined in `Data.Foldable'
infix 4 `elem`
Prelude> elem 'a' "abracadabra"
True
Prelude> [x | x <- "Three Letter Acronym", elem x ['A'..'Z']]
"TLA"
Prelude> :l AcrosChapter9.hs
[1 of 1] Compiling Acros ( AcrosChapter9.hs, interpreted )
Ok, modules loaded: Acros.
*Acros> acros "Three Letter Acronym"
"TLA"
*Acros> acros "National Aeronautics and Space Administration"
"NASA"
11/26/2017
How about a Haskell "get things done" library that is
not physically monolithic but is of a uniform design?
The "where do i get started to do real work" library set?
11/20/2017
We could write, with Parsec a parser for .gitignore files
such that if you provided a file tree, and zero or more
.gitignore files we could provide you with a tree that
represents all the items that are not ignored.
The goal though would be to use that returned tree, in my
case, for a buildtime validator. So maybe for that you
could then call a function which yields all the files
stored within the result tree.
comment: #
multi-line comment start/end: ###
wildcard: *
alternation: [] - we could generate the alternations
directory: /
glob: **
I think it's case-sensitive
rooting: starting with /
this is a folder: anything and /
folder means: walk into tree
file means:
barenames for file anywhere: msbuild.log
every rule is:
walk
zero
every
specific
exact, fuzzy or alternating named directories into tree
and delete
exact, fuzzy or alternating name
where name is file or directory
** not sure if .gitignore cares whether the thing is a
file or directory.
So we get the given tree (how to users make this? and what is
it?) Then we get the [GitIgnore] and generate the list of
items we'll slice out of our tree. We will then traverse the
tree, and each item in our list is an item to remove from the
tree. And then the user needs to not only expect but be
looking forward to using the return value. That could just
be a Rose Tree.
MVP:
take path and one .gitignore with just names
generate tree
parse gitignore for the filenames
traverse the tree, removing each instance of name
return RoseTree representing pruned tree
11/19/2017
Essentially I'm saying: I'll use a parser I built to parse your XPath to build a parser for
XML that will implement your XPath. Maybe I could even figure out how to eliminate the intermediate
step of parsing their XPath into an AST I then read in order to build a parser which implements
the semantics of their XPath.
11/18/2017
I think there should be a way to use expertise built around XPath in Haskell. Right now
I can't find a way to use XPath but instead I see libraries built on their own combinators
etc. Theoretically what we could do is provide an api accepting strings in XPath format
which we then parse using Parsec but which themselves create Parsec parsers which
implement the intention of the XPath.
11/11/2017
:browse! will tell you where you might import something from
Super valuable:
*Matching> :browse Data.Maybe
Data.Maybe.catMaybes :: [Maybe a] -> [a]
Data.Maybe.fromJust :: Maybe a -> a
Data.Maybe.fromMaybe :: a -> Maybe a -> a
Data.Maybe.isJust :: Maybe a -> Bool
Data.Maybe.isNothing :: Maybe a -> Bool
Data.Maybe.listToMaybe :: [a] -> Maybe a
Data.Maybe.mapMaybe :: (a -> Maybe b) -> [a] -> [b]
maybe :: b -> (a -> b) -> Maybe a -> b
Data.Maybe.maybeToList :: Maybe a -> [a]
data Maybe a = Nothing | Just a
*Matching> :browse! Data.Maybe
-- not currently imported
Data.Maybe.catMaybes :: [Maybe a] -> [a]
Data.Maybe.fromJust :: Maybe a -> a
Data.Maybe.fromMaybe :: a -> Maybe a -> a
Data.Maybe.isJust :: Maybe a -> Bool
Data.Maybe.isNothing :: Maybe a -> Bool
Data.Maybe.listToMaybe :: [a] -> Maybe a
Data.Maybe.mapMaybe :: (a -> Maybe b) -> [a] -> [b]
Data.Maybe.maybeToList :: Maybe a -> [a]
-- imported via Prelude
maybe :: b -> (a -> b) -> Maybe a -> b
Just :: a -> Maybe a
data Maybe a = Nothing | Just a
Nothing :: Maybe a
Also, here's the ghci command to show what we've defined at
the console:
*Matching> :show bindings
isItTwo :: Integer -> Bool = _
it :: Maybe Integer = Just 4
What's interesting there is it which I didn't even give a name to.
11/10/2017 later...
Multi-line in ghci:
Prelude> :{
Prelude| let trip :: Integer -> Integer
Prelude| trip = \x -> x * 3
Prelude| :}
Prelude> :t trip
trip :: Integer -> Integer
bonkers!
11/10/2017
Playing around with forM and mapM:
<interactive>:1:1: error: Variable not in scope: forM
*Main> :m Control.Monad
Prelude Control.Monad> forM [1,2,3] (\n -> Some n)
<interactive>:3:21: error:
Data constructor not in scope: Some :: Integer -> m b
Prelude Control.Monad> :t Maybe
<interactive>:1:1: error:
* Data constructor not in scope: Maybe
* Perhaps you meant variable `maybe' (imported from Prelude)
Prelude Control.Monad> :m +Data.Maybe
Prelude Control.Monad Data.Maybe> forM [1,2,3] (\n -> Some n)
<interactive>:6:21: error:
Data constructor not in scope: Some :: Integer -> m b
Prelude Control.Monad Data.Maybe> :browse Data.Maybe
catMaybes :: [Maybe a] -> [a]
fromJust :: Maybe a -> a
fromMaybe :: a -> Maybe a -> a
isJust :: Maybe a -> Bool
isNothing :: Maybe a -> Bool
listToMaybe :: [a] -> Maybe a
mapMaybe :: (a -> Maybe b) -> [a] -> [b]
maybe :: b -> (a -> b) -> Maybe a -> b
maybeToList :: Maybe a -> [a]
data Maybe a = Nothing | Just a
Prelude Control.Monad Data.Maybe> forM [1,2,3] (\n -> Just n)
Just [1,2,3]
Prelude Control.Monad Data.Maybe> mapM (\n -> Just n) [1,2,3]
Just [1,2,3]
11/5/2017
Prelude> :show bindings
x :: Num t => t = _
y :: Num a => a = _
w :: Num a => a = _
z :: Num a => a -> a = _
f :: Fractional a => a = _
x' :: [Char] = _
y' :: [Char] = _
z' :: [Char] = _
f' :: [Char] = _
$trModule :: GHC.Types.Module = _
bigNum :: Num a => a = _
10/30/2017
Spent the week: thinking about the Either Monad as a model for operations
that need to be sequenced but are in the context of failure.
Spent the weekend: first heard and began reading about Indexed Monads
which appear to be Monad sequencing operations in the context of a
state-machine representing the states of some external system.
10/23/2017
I'm also going through Haskell Programming from First Principles
so I've added learn.hs from Chapter 2.
10/18/2017
Interesting - the Line constructor of Doc is used only
in prettify, not in PrettyJSON. PrettyJSON for renderJValue
really only consumes visible constructors, not things like
line, which makes me think that Tab is totally fine as an
idea and will only be used inside of Prettify.
Took my first really real stab at nest!
Realized so many things:
- no need for Tab ctor since nest takes # of spaces
- need to figure out my recursive thing?
- need exhaustive pattern match
- use of replicate
- use of hcat
- is anyone using Prettify.concat?
- VS Code ghci command dies sometimes with lots of
ghc.exes listed in taskmanager
10/17/2017
Ok, so I think the key here is adding a new constructor for Doc, Tab.
nest:: Int -> Doc -> Doc will transform a Doc into one that has Tabs
And, because we've added a constructor for Doc, we need to update all
places that have Doc matches to ensure that they continue to be correct
and complete.
My concern is how to add Tab within a "correct" context, ie. not in the
middle of a concat or union - but type safety should play a role here.
Also, we should defer questions about adding a tab within a string for
once this prototype is done.
Also there's an opportunity here to do this with unit tests!
http://documentup.com/feuerbach/tasty
do we need to import hunit? (yes: tasty-hunit)
After I added tasty to my cabal here's what stack ghci looked like:
PS C:\Users\brodyb\Documents\GitHub\Notes> cd "c:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src"
PS C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src> stack ghci --ghci-options test.hs
clock-0.7.2: configure
stm-2.4.4.1: configure
clock-0.7.2: build
stm-2.4.4.1: build
regex-base-0.93.2: configure
regex-base-0.93.2: build
base-compat-0.9.3: configure
base-compat-0.9.3: build
stm-2.4.4.1: copy/register
regex-base-0.93.2: copy/register
async-2.1.1.1: configure
clock-0.7.2: copy/register
transformers-compat-0.5.1.4: download
async-2.1.1.1: build
regex-tdfa-1.2.2: configure
regex-tdfa-1.2.2: build
transformers-compat-0.5.1.4: configure
async-2.1.1.1: copy/register
transformers-compat-0.5.1.4: build
unbounded-delays-0.1.1.0: configure
transformers-compat-0.5.1.4: copy/register
unbounded-delays-0.1.1.0: build
tagged-0.8.5: download
tagged-0.8.5: configure
base-compat-0.9.3: copy/register
unbounded-delays-0.1.1.0: copy/register
tagged-0.8.5: build
ansi-terminal-0.6.3.1: configure
ansi-terminal-0.6.3.1: build
tagged-0.8.5: copy/register
ansi-terminal-0.6.3.1: copy/register
ansi-wl-pprint-0.6.7.3: configure
ansi-wl-pprint-0.6.7.3: build
ansi-wl-pprint-0.6.7.3: copy/register
optparse-applicative-0.13.2.0: download
optparse-applicative-0.13.2.0: configure
optparse-applicative-0.13.2.0: build
optparse-applicative-0.13.2.0: copy/register
regex-tdfa-1.2.2: copy/register
tasty-0.11.2.5: download
tasty-0.11.2.5: configure
tasty-0.11.2.5: build
tasty-0.11.2.5: copy/register
csv1-0.1.0.0: configure (exe)
Configuring csv1-0.1.0.0...
csv1-0.1.0.0: initial-build-steps (exe)
Completed 14 action(s).
Configuring GHCi with the following packages: csv1
Using main module: 1. Package `csv1' component exe:csv1 with main-is file: C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\Main.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
[1 of 2] Compiling Csv1 ( C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\Csv1.hs, interpreted )
[2 of 2] Compiling Main ( C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\Main.hs, interpreted )
C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\Main.hs:8:26: error:
* Couldn't match type `Text.Parsec.Error.ParseError' with `[Char]'
Expected type: String
Actual type: Text.Parsec.Error.ParseError
* In the first argument of `putStrLn', namely `msg'
In the expression: putStrLn msg
In a case alternative: Left msg -> putStrLn msg
C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\Main.hs:9:30: error:
* Couldn't match type `[String]' with `Char'
Expected type: String
Actual type: [[String]]
* In the first argument of `putStrLn', namely `output'
In the expression: putStrLn output
In a case alternative: Right output -> putStrLn output
Failed, modules loaded: Csv1.
Loaded GHCi configuration from C:\Users\brodyb\AppData\Local\Temp\ghci9724\ghci-script
[1 of 3] Compiling SimpleJSON ( C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\SimpleJSON.hs, interpreted )
[2 of 3] Compiling Prettify ( C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\Prettify.hs, interpreted )
C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\Prettify.hs:123:17: error:
Not in scope: data constructor `Tab'
C:\Users\brodyb\Documents\GitHub\Notes\csv\csv1\src\Prettify.hs:135:17: error:
Not in scope: data constructor `Tab'
Failed, modules loaded: SimpleJSON.
10/16/2017
nest is: Int -> Doc -> Doc whereas
pretty is Int -> Doc -> String so it's like pretty
could call nest optionally and nest merely modifies
a doc, rather than creates a final representation
of it (String)
So, if we read a Doc, how would we see a milemarker
from which to introduce a nesting.
nest might feel a little like punctuate,
is Doc -> [Doc] -> [Doc]
or group, or flatten
We need to be clear on how { is represented in a Doc.
What is the difference, if any, between the left curly
which opens an Object and one that is within a Doc
*TestingNest> renderJValue jvalue''
Concat (Concat (Char '{') (Concat (Concat (Concat (Concat (Concat (Char '"') (Concat (Char 'O') (Concat (Char 'a') (Concat (Char 't') (Concat (Char 'h') (Concat
(Char 'b') (Concat (Char 'r') (Concat (Char 'e') (Concat (Char 'a') (Concat (Char 'k') (Concat (Char 'e') (Char 'r')))))))))))) (Char '"')) (Text ": ")) (Concat
(Concat (Char '"') (Concat (Char 'S') (Concat (Char 'i') (Concat (Char 'n') (Concat (Char 'k') (Concat (Char ' ') (Concat (Char '{') (Concat (Char 'I') (Concat (
Char 'n') (Concat (Char 't') (Concat (Char 'o') (Concat (Char '}') (Concat (Char ' ') (Concat (Char 'S') (Concat (Char 'i') (Concat (Char 'n') (Concat (Char ' ')
(Char 'I')))))))))))))))))) (Char '"'))) (Union (Char ' ') Line))) (Char '}')
*TestingNest> compact $ renderJValue jvalue''
"{\"Oathbreaker\": \"Sink {Into} Sin I\"\n}"
*TestingNest> putStrLn $ compact $ renderJValue jvalue''
{"Oathbreaker": "Sink {Into} Sin I"
}
I can't figure out how to key off of JValue because Doc isn't at that level.
I can't figure out how to key off of Char because at the point when a pretty/compact
or nest is working on a Char there's no context about whether it's in a value or
the formatting to start an Object.
*TestingNest> renderJValue jvalue2
Concat (Concat (Char '{') (Concat (Concat (Concat (Concat (Concat (Concat (Concat (Char '"') (Char 'k')) (Char '"')) (Text ": ")) (Concat (Concat (Char '"') (Con
cat (Char '{') (Concat (Char 'v') (Char '}')))) (Char '"'))) (Char ',')) (Union (Char ' ') Line)) (Concat (Concat (Concat (Concat (Concat (Char '"') (Concat (Cha
r 'k') (Char '2'))) (Char '"')) (Text ": ")) (Text "2.0")) (Union (Char ' ') Line)))) (Char '}')
*TestingNest> compact $ renderJValue jvalue2
"{\"k\": \"{v}\",\n\"k2\": 2.0\n}"
*TestingNest> putStrLn $ compact $ renderJValue jvalue2
{"k": "{v}",
"k2": 2.0
}
Wait, what about escaped double quotes?
or, maybe what I mean is: are we in a string? because if we're not and this Char is a '{' the thing after is indented.
10/13/2017
Work up a sufficiently complicated example in ordre to motivate 'nest'
*TestingNest> putStrLn $ compact $ renderJValue jvalue
[{"Oathbreaker": "Sink Into Sin I",
"Fallujah": "Starlit Path",
"Agoraphobic Nosebleed": "Not a Daughter",
"Lut": "BoyToy"
},
[{"Mechanicum": ["Thanatar Siege Automaton",
"Mars Pattern Reaver Titan"
],
"Vlka Fenryka": ["Leman Russ",
true
]
}
]
]
*TestingNest> putStrLn $ pretty 80 $ renderJValue jvalue
[{"Oathbreaker": "Sink Into Sin I", "Fallujah": "Starlit Path",
"Agoraphobic Nosebleed": "Not a Daughter", "Lut": "BoyToy" },
[{"Mechanicum": ["Thanatar Siege Automaton", "Mars Pattern Reaver Titan" ],
"Vlka Fenryka": ["Leman Russ", true ] } ] ]
For nest, we have a choice, which level would we like to work?
- Char?
- Doc?
- JValue?
Does the suggestion from the author to call it nest and use the parameters
Int -> Doc -> Doc imply placing the function in prettify.hs and then having
it be one step lower in abstraction than renderJValue :: JValue -> Doc?
10/6/2017
Wow, today I forgot my PC at work so I rolled forward by converting the PrettyJSON
project to Haskell for Mac and it just worked. I was able to calmly and confidently
work through each error I faced in turn and solve all of them directly and with
puzzling focused specifically on a set of likely solutions as opposed to getting
huge bewildering errors whose solution could be anything.
It was a very, very cool feeling to know how much I'd learned and how I could
handle the situations presented to me by Haskell. The issues I faced were all
exposing certain symbols through module imports and I was totally able to
figure that out.
10/5/2017
Considering Chapter 5 of Real World Haskell. There are things I still don't
quite get.
* Wasn't super sure about this | syntax:
nicest col a b | (width - least) `fits` a = a
| otherwise = b
where least = min width col
But that's pretty clear to be simple case syntax and each
clause in a | is simply looking for True in order to
return the RHS
* Not super 100% sure about the unicode stuff
* The author really likes infix for stuff like this:
fits :: Int -> String -> Bool
w `fits` _ | w < 0 = False
w `fits` "" = True
w `fits` ('\n':_) = True
w `fits` (c:cs) = (w - 1) `fits` cs
I think it feels awkward
* The author made interesting choices as far as which little
functions to make and how to combine them. It's strange though
because now that I read through the whole file for chapter 5
aka Prettify it feels so clear and straightforward...
I think I *do* like infix syntax for some operators:
foo <> bar
bar </> baz
but less for things like
x `Concat` y
maybe because of the backticks
Questions:
* Can we answer the practice questions?
* fill :: Int -> Doc -> Doc
adds spaces to a doc until it is the given number of columns wide
* nest :: Int -> Doc -> Doc
When we open a parentheses the following lines should be indented by Int
so they are aligned with the opening character until a matching closing
parentheses is found.
* Can we read this, as the author recommends? http://belle.sourceforge.net/doc/hughes95design.pdf
10/3/2017
We're ready to check this out: https://mail.haskell.org/pipermail/beginners/2017-October/017832.html
with response here: https://mail.haskell.org/pipermail/beginners/2017-October/017833.html
10/2/2017
We are on this level
compact $ renderJValue (JObject [("name",JString "value")])
"{\"name\": \"value\"\n}"
*PrettyJSON Prelude> compact $ renderJValue (JBool True)
"true"
*PrettyJSON Prelude> compact $ renderJValue (JArray [(JBool True)])
"[true\n]"
*PrettyJSON Prelude> compact $ renderJValue (JArray [(JBool True), (JBool False)])
"[true,\nfalse\n]"
*PrettyJSON Prelude> compact $ renderJValue (JObject [("name",JArray [(JBool True), (JString "foo")])])
"{\"name\": [true,\n\"foo\"\n]\n}"
*PrettyJSON Prelude> thing = compact $ renderJValue (JObject [("name",JArray [(JBool True), (JString "foo")])])
*PrettyJSON Prelude> :t thing
thing :: String
*PrettyJSON Prelude> thing2 = renderJValue (JObject [("name",JArray [(JBool True), (JString "foo")])])
*PrettyJSON Prelude> :t thing2
thing2 :: Doc
*PrettyJSON> char 'f' <> string "oo"
Concat (Char 'f') (Concat (Concat (Char '"') (Concat (Char 'o') (Char 'o'))) (Char '"'))
*PrettyJSON> char 'f' <> text "oo"
Concat (Char 'f') (Text "oo")
*PrettyJSON> :t text
text :: String -> Doc
*PrettyJSON> :t string
string :: String -> Doc
9/22/2017
Keep on Brody. You are getting this. It's work and it's tiring, but you are totally doing it
and will get to your goal with this work of every day chipping away.
Question: how do I read this type signature into understanding there are two required parameters?
Prelude> :m Numeric
Prelude Numeric> :info showHex
showHex :: (Integral a, Show a) => a -> ShowS
-- Defined in `Numeric'
Prelude Numeric> showHex 4
<interactive>:9:1: error:
* No instance for (Show ShowS) arising from a use of `print'
(maybe you haven't applied a function to enough arguments?)
* In a stmt of an interactive GHCi command: print it
Prelude Numeric> showHex 4 ""
"4"
So you have to pass "" along with 4 to get showHex to work. But the type of showHex
appears to only require one parameter: a which has two typeclass constraints.
here's the answer: ShowS is a thing. If we look at the source for showHex we see
https://hackage.haskell.org/package/base-4.10.0.0/docs/src/Numeric.html#showHex
https://hackage.haskell.org/package/base-4.10.0.0/docs/Text-Show.html#t:ShowS
Prelude Numeric> showHex 4 ""
"4"
Prelude Numeric> :t showHex
showHex :: (Show a, Integral a) => a -> ShowS
Prelude Numeric> x = showHex 4
Prelude Numeric> :t x
x :: ShowS
Prelude Numeric> :info ShowS
type ShowS = String -> String -- Defined in `GHC.Show'
Prelude Numeric> x ""
"4"
Prelude Numeric> x "a"
"4a"
9/20/2017
Having a tough time reading this:
p_series :: Char -> CharParser () a -> Char -> CharParser () [a]
p_series left parser right =
between (char left <* spaces) (char right) $
(parser <* spaces) `sepBy` (char ',' <* spaces)
Problem is:
between is just a function:
*YouCanDoThis> :info between
between ::
Text.Parsec.Prim.Stream s m t =>
Text.Parsec.Prim.ParsecT s u m open
-> Text.Parsec.Prim.ParsecT s u m close
-> Text.Parsec.Prim.ParsecT s u m a
-> Text.Parsec.Prim.ParsecT s u m a
-- Defined in `Text.Parsec.Combinator'
but i can't curry it:
*YouCanDoThis> k = between (char '[')
<interactive>:68:1: error:
* Non type-variable argument
in the constraint: Text.Parsec.Prim.Stream s m Char
(Use FlexibleContexts to permit this)
* When checking the inferred type
k :: forall a close (m :: * -> *) u s.
Text.Parsec.Prim.Stream s m Char =>
Text.Parsec.Prim.ParsecT s u m close
-> Text.Parsec.Prim.ParsecT s u m a
-> Text.Parsec.Prim.ParsecT s u m a
But I got it to work!!!!
I had to do this in ghci:
*YouCanDoThis> :set -XFlexibleContexts
*YouCanDoThis> k = between (char '[')
*YouCanDoThis>
*YouCanDoThis> k = between (char '[')
*YouCanDoThis> :t k
k :: Text.Parsec.Prim.Stream s m Char =>
Text.Parsec.Prim.ParsecT s u m close
-> Text.Parsec.Prim.ParsecT s u m a
-> Text.Parsec.Prim.ParsecT s u m a
*YouCanDoThis> l = between (char '[') (char ']')
*YouCanDoThis> :t l
l :: Text.Parsec.Prim.Stream s m Char =>
Text.Parsec.Prim.ParsecT s u m a
-> Text.Parsec.Prim.ParsecT s u m a
*YouCanDoThis> :browse
p_query :: CharParser () [(String, Maybe String)]
p_pair :: CharParser () (String, Maybe String)
p_pair_app1 :: CharParser () (String, Maybe String)
urlBaseChars :: [Char]
p_char :: CharParser () Char
a_char :: CharParser () Char
a_pair :: CharParser () (String, Maybe String)
p_ha :: CharParser () Char
p_hab :: CharParser () (Char, Char)
p_hex :: CharParser () Char
hexify :: Char -> Char -> Char
mine :: Char -> Char -> String
a_hex :: CharParser () Char
*YouCanDoThis> :t l a_pair
l a_pair
:: Text.Parsec.Prim.ParsecT
[Char] () Data.Functor.Identity.Identity (String, Maybe String)
*YouCanDoThis> m = l a_pair
*YouCanDoThis> parse m "" "[f]"
Right ("f",Nothing)
*YouCanDoThis> parse m "" "[f=%21]"
Right ("f",Just "!")
Explanation of FlexibleContexts:
https://stackoverflow.com/questions/31251163/what-is-the-flexiblecontexts-extension-is-good-for-could-you-please-explain-it
Ok, so huge: we got currying to work for parsers, which will allow us to
build them up incrementally which we couldn't before which made them seem
more mysterious than they needed to be.
Now: how and why are these different:
m :: Text.Parsec.Prim.ParsecT
[Char] () Data.Functor.Identity.Identity (String, Maybe String)
p_series :: Char -> CharParser () a -> Char -> CharParser () [a]
p_series left parser right =
between (char left <* spaces) (char right) $
(parser <* spaces) `sepBy` (char ',' <* spaces)
m is curried between.