packages feed

FirstPrelude (empty) → 0.1.1.0

raw patch · 5 files changed

+344/−0 lines, 5 filesdep +basesetup-changed

Dependencies added: base

Files

+ CHANGELOG.md view
@@ -0,0 +1,8 @@+# Revision history for FirstPrelude++## 0.1.1.0+* Added in (^) :: Integer -> Integer -> Integer++## 0.1.0.0++* First version. Released on an unsuspecting world.
+ FirstPrelude.cabal view
@@ -0,0 +1,62 @@+cabal-version:      2.4+name:               FirstPrelude++-- The package version.+-- See the Haskell package versioning policy (PVP) for standards+-- guiding when and how versions should be incremented.+-- https://pvp.haskell.org+-- PVP summary:      +-+------- breaking API changes+--                   | | +----- non-breaking API additions+--                   | | | +--- code changes with no API change+version:            0.1.1.0++-- A short (one-line) description of the package.+synopsis:           A version of Prelude suitable for teaching.++description:       The design goals are to simplify considerably the Prelude library so that basic functional programming can be taught without having to explain type classes.  I have observed in several years of teaching Haskell that many beginner mistakes which in a language like ML would result in a clear error message instead result in an error message about a lack of type class instances. This is unfortunate as type classes cannot easily be taught immediately and so beginners are left without as much support until they learn more topics. FirstPrelude is designed to simplify away as much of this as possible by using very few type classes and making a few other simplifying choices. The goal is then for students to switch to regular Prelude later in the course. A synposis of the changes can be found on the project homepage.++-- URL for the project homepage or repository.+homepage:           https://github.com/dorchard/FirstPrelude++-- A URL where users can report bugs.+-- bug-reports:++-- The license under which the package is released.+license:            BSD-3-Clause++-- The file containing the license text.+license-file:       LICENSE++-- The package author(s).+author:             dorchard++-- An email address to which users can send suggestions, bug reports, and patches.+maintainer:         dom.orchard@gmail.com++-- A copyright notice.+-- copyright:+-- category:++-- Extra files to be distributed with the package, such as examples or a README.+extra-source-files: CHANGELOG.md++build-type:    Simple++library+    -- Modules exported by the library.+    exposed-modules:  FirstPrelude++    -- Modules included in this library but not exported.+    -- other-modules:++    -- LANGUAGE extensions used by modules in this package.+    -- other-extensions:++    -- Other library packages from which modules are imported.+    build-depends:    base >= 4.0.0.0 && < 4.16.5.0++    -- Directories containing source files.+    hs-source-dirs:   src++    -- Base language which the package is written in.+    default-language: Haskell2010
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2023, dorchard++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of dorchard nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/FirstPrelude.hs view
@@ -0,0 +1,242 @@+{-# LANGUAGE NoImplicitPrelude #-}+{-# LANGUAGE ExplicitNamespaces #-}++{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE UndecidableInstances #-}+{-# LANGUAGE TypeOperators #-}++-----------------------------------------------------------------------------+-- |+-- Module      :  FirstPrelude+-- Copyright   :  (c) University of Kent 2022+-- License     :  BSD-style+--+-- Maintainer  :  Dominic Orchard+-- Stability   :  experimental+-- Portability :  portable+--+-- FirstPrelude is a non-exhaustive replacement for Prelude aimed at+-- absolute beginners to Haskell. It largely tries to bypass the need+-- for type classes (arithmetic is specialised to Integers), it+-- provides some simplifications to Prelude, and provides some custom+-- error messages.+--+-----------------------------------------------------------------------------++module FirstPrelude (++    -- * Standard types++    -- ** Basic data types+    Bool(False, True),+    (&&), (||), not, otherwise,++    Maybe(Nothing, Just),+    maybe,++    Either(Left, Right),+    either,++    Char, String,++    -- *** Tuples+    fst, snd, curry, uncurry,++    -- ** Basic comparators (specialised to Integer)+    -- and enumerations+    (==), (/=),+    (<), (<=), (>=), (>), max, min,+    succ, pred,+    enumFrom, enumFromThen,+    enumFromTo, enumFromThenTo,++    -- ** Numbers++    -- *** Only Integers for now folks+    Integer,++    -- *** Numeric operations+    (+), (-), (*), negate, abs, signum, fromInteger,+    quot, rem, div, mod, quotRem, divMod, toInteger,+    (^),++    -- ** Monads and functors+    fmap,+    (>>=), (>>), return,+    fail,++    -- ** Higher-order functions on lists+    foldr,     -- :: (a -> b -> b) -> b -> [a] -> b+    foldl,     -- :: (b -> a -> b) -> b -> [a] -> b++    -- ** Miscellaneous functions+    id, const, (.), flip, ($), until,+    asTypeOf, error, errorWithoutStackTrace, undefined,+    seq,++    -- * List operations+    List.map, (List.++), List.filter,+    List.head, List.last, List.tail, List.init, (List.!!),+    null, length,+    List.reverse,+    -- *** Scans+    List.scanl, List.scanl1, List.scanr, List.scanr1,+    -- *** Infinite lists+    List.iterate, List.repeat, List.replicate, List.cycle,+    -- ** Sublists+    List.take, List.drop,+    List.takeWhile, List.dropWhile,+    List.span, List.break,+    List.splitAt,+    -- ** Zipping and unzipping lists+    List.zip, List.zip3,+    List.zipWith, List.zipWith3,+    List.unzip, List.unzip3,+    -- ** Functions on strings+    List.lines, List.words, List.unlines, List.unwords,++    -- * Show / Read (simplified)+    Show(showsPrec, show),+    read,++    -- * Basic Input and output+    IO,+    -- ** Simple I\/O operations+    -- All I/O functions defined here are character oriented.  The+    -- treatment of the newline character will vary on different systems.+    -- For example, two characters of input, return and linefeed, may+    -- read as a single newline character.  These functions cannot be+    -- used portably for binary I/O.+    -- *** Output functions+    putChar,+    putStr, putStrLn, print,+    -- *** Input functions+    getChar,+    getLine, getContents, interact,+    -- *** Files+    FilePath,+    readFile, writeFile, appendFile, readIO, readLn,+    -- ** Exception handling in the I\/O monad+    IOError, ioError, userError,++  ) where++import qualified Control.Monad as Monad+import System.IO+import System.IO.Error+import qualified Data.List as List+import Data.Either+import Data.Functor     ( (<$>) )+import Data.Maybe+import Data.Tuple++import GHC.Base hiding ( foldr, mapM, sequence, Eq(..), Ord(..), Monad(..) )+import qualified Text.Read as Read+import qualified GHC.Enum as Enum+import qualified GHC.Num as Num+import GHC.Num(Integer)+import qualified GHC.Real as NumR+import qualified Data.Ord as Ord+import qualified Data.Eq  as Eq+import GHC.Show++import GHC.TypeLits++-- Re-export some monomorphised things from foldable+import qualified Data.Foldable as Foldable++-- Avoids the Int/Integer problem+length :: [a] -> Integer+length []     = 0+length (_:xs) = 1 + length xs++-- ** Monomorphised comparisons and arithmetic++(==), (/=), (<), (<=), (>=), (>) :: Integer -> Integer -> Bool+(==) = (Eq.==)+(/=) = (Eq./=)+(<)  = (Ord.<)+(<=) = (Ord.<=)+(>=) = (Ord.>=)+(>)  = (Ord.>)++max, min :: Integer -> Integer -> Integer+max = Ord.max+min = Ord.min++succ, pred :: Integer -> Integer+succ = Enum.succ+pred = Enum.pred++enumFrom :: Integer -> [Integer]+enumFrom = Enum.enumFrom++enumFromThen :: Integer -> Integer -> [Integer]+enumFromThen = Enum.enumFromThen++enumFromTo :: Integer -> Integer -> [Integer]+enumFromTo = Enum.enumFromTo++enumFromThenTo :: Integer -> Integer -> Integer -> [Integer]+enumFromThenTo = Enum.enumFromThenTo++(+), (-), (*), quot, rem, div, mod :: Integer -> Integer -> Integer+(+) = (Num.+)+(-) = (Num.-)+(*) = (Num.*)+quot = NumR.quot+rem = NumR.rem+div = NumR.div+mod = NumR.mod++negate, abs, signum, fromInteger, toInteger :: Integer -> Integer+negate = Num.negate+abs    = Num.abs+signum = Num.signum+fromInteger = id+toInteger   = id++quotRem, divMod :: Integer -> Integer -> (Integer, Integer)+quotRem = NumR.quotRem+divMod  = NumR.divMod++(^) :: Integer -> Integer -> Integer+(^) = (NumR.^)++-- ** Monomorphised fold things++null :: [a] -> Bool+null = Foldable.null++foldl :: (b -> a -> b) -> b -> [a] -> b+foldl = Foldable.foldl++foldr :: (a -> b -> b) -> b -> [a] -> b+foldr = Foldable.foldr++-- ** Monomorphised monads++return :: a -> IO a+return = Monad.return++(>>) :: IO a -> IO b -> IO b+(>>) = (Monad.>>)++(>>=) :: IO a -> (a -> IO b) -> IO b+(>>=) = (Monad.>>=)++fail :: String -> IO a+fail = (Monad.fail)++-- ** Show gets a fancy error message++read :: String -> Integer+read = Read.read++instance TypeError+           (Text "Cannot show (pretty print) functions (yours is of type "+           :<>: ShowType a :<>: Text " -> " :<>: ShowType b :<>: Text ")"+           :$$: Text "" :$$: Text "Perhaps there is a missing argument?" :$$: Text "")+           => Show (a -> b) where+   show = undefined