Skip to content

Commit

Permalink
Use MiniPrelude instead of Prelude in a number of places.
Browse files Browse the repository at this point in the history
Using Prelude drags in the bloated Text.Read modules.
  • Loading branch information
augustss committed Sep 20, 2024
1 parent 368d496 commit 832fac0
Show file tree
Hide file tree
Showing 64 changed files with 4,568 additions and 4,629 deletions.
1 change: 1 addition & 0 deletions MicroHs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ executable mhs
Data.Integer
Compat
PrimTable
MHSPrelude
System.IO.MD5
System.IO.Serialize
System.IO.TimeMilli
Expand Down
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Add mask&co to exceptions
* Make deriving refer to identifiers that don't need to be in scope
* Add reductions for underapplied K2,K3,K4
* Move some Typeable instances from the class file to ST&co (makes it leaner)

Bugs:
* Missing IO in ccall shows wrong location
Expand Down
8,947 changes: 4,352 additions & 4,595 deletions generated/mhs.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions ghc/MHSPrelude.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MHSPrelude(module Prelude) where
import Prelude
1 change: 1 addition & 0 deletions lib/Control/Exception.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Control.Exception(
--
ArithException(..),
) where
import Prelude(); import MiniPrelude
import Control.Exception.Internal
import {-# SOURCE #-} Data.Typeable
import System.IO.Unsafe
Expand Down
2 changes: 1 addition & 1 deletion lib/Control/Monad/ST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Control.Monad.ST(
ST,
runST,
) where
import Prelude
import Prelude(); import MiniPrelude
import Primitives(primPerformIO)
import Control.Monad.ST_Type

Expand Down
2 changes: 1 addition & 1 deletion lib/Data/ByteString/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Data.ByteString.Internal(module Data.ByteString.Internal) where
import Prelude hiding(length)
import Prelude(); import MiniPrelude hiding(length)
import Data.Word(Word8)

data ByteString -- primitive type
Expand Down
2 changes: 1 addition & 1 deletion lib/Data/STRef.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Data.STRef(
STRef,
newSTRef, readSTRef, writeSTRef, modifySTRef,
) where
import Prelude
import Prelude(); import MiniPrelude
import Control.Monad.ST_Type
import Data.IORef

Expand Down
2 changes: 1 addition & 1 deletion lib/Data/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Data.Text(
append,
head,
) where
import Prelude hiding(head)
import Prelude(); import MiniPrelude hiding(head)
import Data.Monoid
import Data.Semigroup
import Data.String
Expand Down
2 changes: 1 addition & 1 deletion lib/Data/Type/Equality.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Data.Type.Equality(module Data.Type.Equality) where
import Prelude
import Prelude(); import MiniPrelude

type (:~:) :: forall k . k -> k -> Type
data a :~: b = (a ~ b) => Refl
Expand Down
4 changes: 3 additions & 1 deletion lib/Data/Typeable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ module Data.Typeable (
typeRepTyCon,
typeRepArgs,
) where
import Prelude(); import MiniPrelude
import Primitives
import Prelude
import Control.Monad.ST
import Data.Double
import Data.Integer
import Data.IORef
import Data.Proxy
import Data.Ratio
Expand Down
1 change: 1 addition & 0 deletions lib/Data/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Data.Version(
showVersion,
makeVersion
) where
import Prelude(); import MiniPrelude
import Data.List(intercalate)

data Version = Version { versionBranch :: [Int] }
Expand Down
2 changes: 1 addition & 1 deletion lib/Data/Void.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Data.Void(module Data.Void) where
import Prelude
import Prelude(); import MiniPrelude

data Void

Expand Down
2 changes: 1 addition & 1 deletion lib/Debug/Trace.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Debug.Trace(module Debug.Trace) where
import Prelude
import Prelude(); import MiniPrelude
import Primitives

trace :: forall a . String -> a -> a
Expand Down
2 changes: 1 addition & 1 deletion lib/Foreign/Marshal/Array.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Foreign.Marshal.Array(module Foreign.Marshal.Array) where
import Prelude
import Prelude(); import MiniPrelude
import Foreign.Ptr
import Foreign.Storable
import Foreign.Marshal.Alloc
Expand Down
2 changes: 1 addition & 1 deletion lib/Foreign/Marshal/Utils.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Foreign.Marshal.Utils(module Foreign.Marshal.Utils) where
import Prelude
import Prelude(); import MiniPrelude
import Foreign.Marshal.Alloc
import Foreign.C.Types
import Foreign.Ptr
Expand Down
62 changes: 62 additions & 0 deletions lib/MiniPrelude.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module MiniPrelude(
module Control.Applicative,
module Control.Error,
module Control.Monad,
module Data.Bool,
module Data.Char,
module Data.Enum,
module Data.Eq,
module Data.Either,
module Data.Function,
module Data.Functor,
module Data.Ord,
module Data.Int,
module Data.Integral,
module Data.List,
module Data.Maybe,
module Data.Monoid,
module Data.Num,
module Data.Records,
module Data.String,
module Data.Tuple,
module System.IO,
module Text.Show,
usingMhs, _wordSize, _isWindows,
) where
import Prelude()
import Control.Applicative(Applicative(..))
import Control.Error
import Control.Monad
import Data.Bool
import Data.Char
import Data.Enum
import Data.Eq
import Data.Either
import Data.Function
import Data.Functor
import Data.Ord
import Data.Int
import Data.Integral
import Data.List([](..), map, (++), filter, head, last, tail, init, null, length, (!!),
reverse, foldl, foldl1, foldr, foldr1, and, or, any, all,
sum, product, concat, concatMap, maximum, minimum,
scanl, scanl1, scanr, scanr1, iterate, repeat, replicate, cycle,
take, drop, splitAt, takeWhile, dropWhile, span, break,
elem, notElem, lookup, zip, zip3, zipWith, zipWith3, unzip, unzip3,
lines, words, unlines, unwords)
import Data.Maybe
import Data.Monoid
import Data.Num
import Data.Records
import Data.String
import Data.Tuple
import System.IO(IO, putChar, putStr, putStrLn, print, getLine, getContents, interact,
FilePath, readFile, writeFile, appendFile,
cprint, cuprint)
import Text.Show(Show(..), ShowS, shows, showChar, showString, showParen)
import Text.Show
import Primitives(_wordSize, _isWindows)

-- So we can detect mhs vs ghc
usingMhs :: Bool
usingMhs = True
1 change: 1 addition & 0 deletions lib/System/Cmd.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module System.Cmd(system) where
import Prelude(); import MiniPrelude
import Foreign.C.String
import System.Exit

Expand Down
1 change: 1 addition & 0 deletions lib/System/Compress.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module System.Compress(compress) where
import Prelude(); import MiniPrelude
import Foreign.C.String
import Foreign.C.Types
import Foreign.Marshal.Alloc
Expand Down
2 changes: 1 addition & 1 deletion lib/System/Directory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module System.Directory(
copyFile,
getHomeDirectory,
) where
import Prelude
import Prelude(); import MiniPrelude
import Control.Exception(bracket)
import Control.Monad(when)
import Foreign.C.String
Expand Down
3 changes: 2 additions & 1 deletion lib/System/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ module System.Environment(
lookupEnv,
getEnv,
) where
import Prelude
import Prelude(); import MiniPrelude
import Primitives
import Foreign.C.String
import Foreign.Ptr
import System.IO

-- primArgRef returns an array containing a list of strings.
-- The first element is the program name, the rest are the arguments.
Expand Down
1 change: 1 addition & 0 deletions lib/System/Exit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module System.Exit(
exitSuccess,
die,
) where
import Prelude(); import MiniPrelude
import Control.Exception
import Data.Typeable
import System.IO
Expand Down
2 changes: 1 addition & 1 deletion lib/System/IO/MD5.hs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-- Copyright 2023 Lennart Augustsson
-- See LICENSE file for full license.
module System.IO.MD5(MD5CheckSum, md5File, md5Handle, md5String, md5Combine) where
import Prelude(); import MiniPrelude
import Primitives(primPerformIO)
import Prelude
import Data.Word
import Foreign.C.String
import Foreign.Marshal.Alloc
Expand Down
1 change: 1 addition & 0 deletions lib/System/IO/Serialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module System.IO.Serialize(
writeSerialized, writeSerializedCompressed,
readSerialized,
) where
import Prelude(); import MiniPrelude
import Primitives(Ptr)
import System.IO_Handle
import System.IO
Expand Down
1 change: 1 addition & 0 deletions lib/System/IO/TimeMilli.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module System.IO.TimeMilli(getTimeMilli) where
import Prelude(); import MiniPrelude

foreign import ccall "GETTIMEMILLI" c_getTimeMilli :: IO Int

Expand Down
2 changes: 1 addition & 1 deletion lib/System/Process.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module System.Process(callCommand) where
import Prelude
import Prelude(); import MiniPrelude
import Control.Monad(when)
import Foreign.C.String

Expand Down
77 changes: 77 additions & 0 deletions mhs/MHSPrelude.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module MHSPrelude(
module Control.Applicative,
module Control.Error,
module Control.Monad,
module Control.Monad.Fail,
module Data.Bool,
module Data.Bounded,
module Data.Char,
module Data.Double,
module Data.Either,
module Data.Enum,
module Data.Eq,
module Data.Fractional,
module Data.Function,
module Data.Functor,
module Data.Int,
module Data.Integer,
module Data.Integral,
module Data.List,
module Data.Maybe,
module Data.Monoid,
module Data.Num,
module Data.Ord,
module Data.Ratio,
module Data.Real,
module Data.Records,
module Data.String,
module Data.Tuple,
module System.IO,
module Text.Show,
usingMhs, _wordSize, _isWindows,
) where
import Prelude()
import Control.Applicative(Applicative(..))
import Control.Error(error, undefined)
import Control.Monad(Monad(..), mapM, mapM_, sequence, sequence_, (=<<))
import Control.Monad.Fail(MonadFail(..))
import Data.Bool(Bool(..), (&&), (||), not, otherwise)
import Data.Bounded(Bounded(..))
import Data.Char(Char, String)
import Data.Double(Double)
import Data.Either(Either(..), either)
import Data.Enum(Enum(..))
import Data.Eq(Eq(..))
import Data.Fractional(Fractional(..), (^^))
import Data.Function(id, const, (.), flip, ($), seq, ($!), until, asTypeOf)
import Data.Functor(Functor(..), (<$>))
import Data.Int(Int)
import Data.Int.Instances
import Data.Integer(Integer)
import Data.Integral(Integral(..), fromIntegral, gcd, lcm, even, odd, (^))
import Data.List([](..), map, (++), filter, head, last, tail, init, null, length, (!!),
reverse, foldl, foldl1, foldr, foldr1, and, or, any, all,
sum, product, concat, concatMap, maximum, minimum,
scanl, scanl1, scanr, scanr1, iterate, repeat, replicate, cycle,
take, drop, splitAt, takeWhile, dropWhile, span, break,
elem, notElem, lookup, zip, zip3, zipWith, zipWith3, unzip, unzip3,
lines, words, unlines, unwords)
import Data.Maybe(Maybe(..), maybe)
import Data.Monoid(Monoid(..))
import Data.Num(Num(..), subtract)
import Data.Ord(Ord(..), Ordering(..))
import Data.Ratio(Rational)
import Data.Real(Real(..), realToFrac)
import Data.Records -- XXX redo this somehow
import Data.String(IsString(..), lines, unlines, words, unwords)
import Data.Tuple(()(..), fst, snd, curry, uncurry)
import Data.Word(Word)
import System.IO(IO, putChar, putStr, putStrLn, print, getLine, getContents, interact,
FilePath, readFile, writeFile, appendFile,
cprint, cuprint)
import Text.Show(Show(..), ShowS, shows, showChar, showString, showParen)
import Primitives(_wordSize, _isWindows)

-- So we can detect mhs vs ghc
usingMhs :: Bool
usingMhs = True
2 changes: 1 addition & 1 deletion mhs/System/Console/SimpleReadline.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module System.Console.SimpleReadline(
getInputLineHist,
getInputLineHistComp,
) where
import Prelude
import Prelude(); import MiniPrelude
import Control.Monad
import Data.Char
import System.IO
Expand Down
1 change: 1 addition & 0 deletions paths/Paths_MicroHs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Paths_MicroHs(
version,
getDataDir,
) where
import Prelude(); import MiniPrelude
import Data.Version

getDataDir :: IO FilePath
Expand Down
1 change: 1 addition & 0 deletions src/MicroHs/Abstract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module MicroHs.Abstract(
compileOpt,
-- reduce,
) where
import Prelude(); import MHSPrelude
import MicroHs.Ident
import MicroHs.Exp
import MicroHs.Expr(Lit(..))
Expand Down
1 change: 1 addition & 0 deletions src/MicroHs/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module MicroHs.Compile(
mhsVersion,
getMhsDir,
) where
import Prelude(); import MHSPrelude
import Data.Char
import Data.List
import Data.Maybe
Expand Down
1 change: 1 addition & 0 deletions src/MicroHs/CompileCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module MicroHs.CompileCache(
addPackage, getCompMdls, getPkgs,
saveCache, loadCached,
) where
import Prelude(); import MHSPrelude
import MicroHs.Desugar(LDef)
import MicroHs.Expr(IdentModule)
import MicroHs.Ident(showIdent)
Expand Down
2 changes: 1 addition & 1 deletion src/MicroHs/Deriving.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module MicroHs.Deriving(expandField, doDeriving, mkGetName) where
import Prelude
import Prelude(); import MHSPrelude
--import Control.Monad
import Data.Char
import Data.Function
Expand Down
1 change: 1 addition & 0 deletions src/MicroHs/Desugar.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module MicroHs.Desugar(
LDef, showLDefs,
encodeInteger,
) where
import Prelude(); import MHSPrelude
import Data.Char
import Data.Function
import Data.Integer(_integerToIntList)
Expand Down
1 change: 1 addition & 0 deletions src/MicroHs/EncodeData.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module MicroHs.EncodeData(
encIf,
encList,
) where
import Prelude(); import MHSPrelude
import Data.List
import MicroHs.Exp
import MicroHs.Expr(Con(..), Lit(..))
Expand Down
Loading

0 comments on commit 832fac0

Please sign in to comment.