1
+ {-# LANGUAGE CPP #-}
2
+
1
3
module Functora.Prelude
2
4
( -- * Reexport
3
5
-- $reexport
4
6
module X ,
5
7
LiftTH ,
8
+ Unicode ,
6
9
7
10
-- * Show
8
11
-- $show
@@ -351,16 +354,33 @@ import UnliftIO as X
351
354
import UnliftIO.MVar as X (modifyMVar )
352
355
import Witch.Mini as X
353
356
import qualified Prelude
357
+ #if defined(__GHCJS__) || defined(ghcjs_HOST_OS) || defined(wasi_HOST_OS)
358
+ import qualified Data.JSString as JS
359
+ #endif
354
360
355
361
-- $reexport
356
362
-- Reexport
357
363
358
364
type LiftTH = TH. Lift
359
365
366
+ #if defined(__GHCJS__) || defined(ghcjs_HOST_OS) || defined(wasi_HOST_OS)
367
+ type Unicode = JS. JSString
368
+ #else
369
+ type Unicode = Text
370
+ #endif
371
+
360
372
-- $show
361
373
-- Show
362
374
363
- inspect :: forall dst src . (Show src , Data src , IsString dst ) => src -> dst
375
+ inspect ::
376
+ forall dst src .
377
+ ( Show src ,
378
+ Data src ,
379
+ Typeable dst ,
380
+ IsString dst
381
+ ) =>
382
+ src ->
383
+ dst
364
384
inspect =
365
385
display @ dst @ src
366
386
. Syb. everywhere (Syb. mkT prettyByteString)
@@ -404,7 +424,7 @@ defaultRatioFormat =
404
424
405
425
inspectRatio ::
406
426
forall a b .
407
- ( From String a ,
427
+ ( IsString a ,
408
428
From b Integer ,
409
429
Integral b
410
430
) =>
@@ -432,14 +452,14 @@ inspectRatio fmt signedRational =
432
452
>= limit
433
453
&& ratioFormatDecimalPlacesTotalLimitOverflow fmt
434
454
== DecimalPlacesOverflowExponent ->
435
- from @ String @ a
455
+ fromString @ a
436
456
. Scientific. formatScientific Scientific. Exponent Nothing
437
457
. either fst fst
438
458
. Scientific. fromRationalRepetend Nothing
439
459
$ signedNumerator
440
460
% signedDenominator
441
461
_ ->
442
- from @ String @ a
462
+ fromString @ a
443
463
$ (if signedRational < 0 then " -" else mempty )
444
464
<> Prelude. shows
445
465
quotient
@@ -481,7 +501,7 @@ inspectRatio fmt signedRational =
481
501
482
502
inspectRatioDef ::
483
503
forall a b .
484
- ( From String a ,
504
+ ( IsString a ,
485
505
From b Integer ,
486
506
Integral b
487
507
) =>
@@ -496,8 +516,18 @@ roundRational decimalPlaces input =
496
516
where
497
517
mult = 10 ^ decimalPlaces
498
518
499
- display :: forall dst src . (Show src , Typeable src , IsString dst ) => src -> dst
519
+ display ::
520
+ forall dst src .
521
+ ( Show src ,
522
+ Typeable src ,
523
+ Typeable dst ,
524
+ IsString dst
525
+ ) =>
526
+ src ->
527
+ dst
500
528
display x
529
+ | Just HRefl <- typeOf x `eqTypeRep` typeRep @ dst =
530
+ x
501
531
| Just HRefl <- typeOf x `eqTypeRep` typeRep @ String =
502
532
fromString x
503
533
| Just HRefl <- typeOf x `eqTypeRep` typeRep @ Text =
@@ -515,7 +545,18 @@ display x
515
545
(fromString . from @ TL. Text @ String )
516
546
(TLE. decodeUtf8' x)
517
547
| otherwise =
548
+ defDisplay
549
+ where
550
+ #if defined(__GHCJS__) || defined(ghcjs_HOST_OS) || defined(wasi_HOST_OS)
551
+ defDisplay
552
+ | Just HRefl <- typeOf x `eqTypeRep` typeRep @ JS. JSString =
553
+ fromString $ JS. unpack x
554
+ | otherwise =
555
+ Universum. show x
556
+ #else
557
+ defDisplay =
518
558
Universum. show x
559
+ #endif
519
560
520
561
prettyByteString :: ByteString -> ByteString
521
562
prettyByteString raw =
@@ -761,7 +802,7 @@ utf8FromLatin1 raw =
761
802
762
803
qq ::
763
804
forall inp out e .
764
- ( From String inp ,
805
+ ( IsString inp ,
765
806
Typeable out ,
766
807
TH. Lift out ,
767
808
Data e ,
@@ -785,7 +826,7 @@ qq parser =
785
826
<> " ) with the failure ("
786
827
<> inspect e
787
828
<> " )"
788
- case parser $ from @ String @ inp x0 of
829
+ case parser $ fromString @ inp x0 of
789
830
Left e -> fatal e
790
831
Right x -> TH. lift x
791
832
}
@@ -1031,7 +1072,8 @@ prevEnum x
1031
1072
1032
1073
type Textual mono =
1033
1074
( Seq. Textual mono ,
1034
- Container mono
1075
+ Container mono ,
1076
+ Typeable mono
1035
1077
)
1036
1078
1037
1079
strip :: (Textual mono ) => mono -> mono
0 commit comments