tip-haskell-frontend-0.2: Convert from Haskell to Tip

Safe HaskellSafe
LanguageHaskell2010

Tip.Prelude

Contents

Description

A drop-in replacement for Prelude with unfoldings exported, oriented towards Nats

Synopsis

Documentation

module Tip

Booleans

(&&) :: Bool -> Bool -> Bool infixr 3 Source

(||) :: Bool -> Bool -> Bool infixr 2 Source

Nat functions

data Nat Source

Constructors

Z 
S Nat 

(+) :: Nat -> Nat -> Nat infixl 6 Source

(*) :: Nat -> Nat -> Nat infixl 7 Source

(^) :: Nat -> Nat -> Nat infixr 8 Source

Truncated subtraction

(-) :: Nat -> Nat -> Nat infixl 6 Source

(<) :: Nat -> Nat -> Bool infix 4 Source

(<=) :: Nat -> Nat -> Bool infix 4 Source

(>) :: Nat -> Nat -> Bool infix 4 Source

(>=) :: Nat -> Nat -> Bool infix 4 Source

(==) :: Nat -> Nat -> Bool infix 4 Source

(/=) :: Nat -> Nat -> Bool infix 4 Source

max :: Nat -> Nat -> Nat Source

min :: Nat -> Nat -> Nat Source

List functions on nats

take :: Nat -> [a] -> [a] Source

drop :: Nat -> [a] -> [a] Source

splitAt :: Nat -> [a] -> ([a], [a]) Source

length :: [a] -> Nat Source

delete :: Nat -> [Nat] -> [Nat] Source

deleteAll :: Nat -> [Nat] -> [Nat] Source

count :: Nat -> [Nat] -> Nat Source

nub :: [Nat] -> [Nat] Source

index :: [a] -> Nat -> Maybe a Source

elem :: Nat -> [Nat] -> Bool Source

insert :: Nat -> [Nat] -> [Nat] Source

isort :: [Nat] -> [Nat] Source

eqList :: [Nat] -> [Nat] -> Bool Source

sum :: [Nat] -> Nat Source

lookup :: Nat -> [(Nat, b)] -> Maybe b Source

Int functions

zeq :: Int -> Int -> Bool Source

zne :: Int -> Int -> Bool Source

zle :: Int -> Int -> Bool Source

zlt :: Int -> Int -> Bool Source

zgt :: Int -> Int -> Bool Source

zge :: Int -> Int -> Bool Source

zmax :: Int -> Int -> Int Source

zmin :: Int -> Int -> Int Source

List functions on Ints

ztake :: Int -> [a] -> [a] Source

zdrop :: Int -> [a] -> [a] Source

zsplitAt :: Int -> [a] -> ([a], [a]) Source

zlength :: [a] -> Int Source

zdelete :: Int -> [Int] -> [Int] Source

zdeleteAll :: Int -> [Int] -> [Int] Source

zcount :: Int -> [Int] -> Nat Source

zzcount :: Int -> [Int] -> Int Source

znub :: [Int] -> [Int] Source

zindex :: [a] -> Int -> Maybe a Source

zelem :: Int -> [Int] -> Bool Source

zinsert :: Int -> [Int] -> [Int] Source

zisort :: [Int] -> [Int] Source

zeqList :: [Int] -> [Int] -> Bool Source

zsum :: [Int] -> Int Source

zlookup :: Int -> [(Int, b)] -> Maybe b Source

Polymorphic lists functions

null :: [a] -> Bool Source

(++) :: [a] -> [a] -> [a] Source

reverse :: [a] -> [a] Source

zip :: [a] -> [b] -> [(a, b)] Source

filter :: (a -> Bool) -> [a] -> [a] Source

map :: (a -> b) -> [a] -> [b] Source

concat :: [[a]] -> [a] Source

concatMap :: (a -> [b]) -> [a] -> [b] Source

foldl :: (b -> a -> b) -> b -> [a] -> b Source

foldr :: (a -> b -> b) -> b -> [a] -> b Source

Lists and booleans

or :: [Bool] -> Bool Source

all :: (a -> Bool) -> [a] -> Bool Source

any :: (a -> Bool) -> [a] -> Bool Source

takeWhile :: (a -> Bool) -> [a] -> [a] Source

dropWhile :: (a -> Bool) -> [a] -> [a] Source

id :: a -> a Source

Miscellaneous

const :: a -> b -> a Source

(.) :: (b -> c) -> (a -> b) -> a -> c infixr 9 Source

flip :: (a -> b -> c) -> b -> a -> c Source

($) :: (a -> b) -> a -> b infixr 0 Source

maybe :: b -> (a -> b) -> Maybe a -> b Source

either :: (a -> c) -> (b -> c) -> Either a b -> c Source

fst :: (a, b) -> a Source

snd :: (a, b) -> b Source

data Bool :: *

Constructors

False 
True 

Instances

data Maybe a :: * -> *

The Maybe type encapsulates an optional value. A value of type Maybe a either contains a value of type a (represented as Just a), or it is empty (represented as Nothing). Using Maybe is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error.

The Maybe type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing. A richer error monad can be built using the Either type.

Constructors

Nothing 
Just a 

Instances

Monad Maybe 
Functor Maybe 
Applicative Maybe 
Foldable Maybe 
Traversable Maybe 
Generic1 Maybe 
Alternative Maybe 
MonadPlus Maybe 
Eq1 Maybe 
Ord1 Maybe 
Read1 Maybe 
Show1 Maybe 
UserOfRegs r a => UserOfRegs r (Maybe a) 
DefinerOfRegs r a => DefinerOfRegs r (Maybe a) 
Eq a => Eq (Maybe a) 
Ord a => Ord (Maybe a) 
Show a => Show (Maybe a) 
Generic (Maybe a) 
Arbitrary a => Arbitrary (Maybe a) 
CoArbitrary a => CoArbitrary (Maybe a) 
Monoid a => Monoid (Maybe a)

Lift a semigroup into Maybe forming a Monoid according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be turned into a monoid simply by adjoining an element e not in S and defining e*e = e and e*s = s = s*e for all s ∈ S." Since there is no "Semigroup" typeclass providing just mappend, we use Monoid instead.

Outputable a => Outputable (Maybe a) 
Lift a => Lift (Maybe a) 
type Rep1 Maybe = D1 D1Maybe ((:+:) (C1 C1_0Maybe U1) (C1 C1_1Maybe (S1 NoSelector Par1))) 
type Rep (Maybe a) = D1 D1Maybe ((:+:) (C1 C1_0Maybe U1) (C1 C1_1Maybe (S1 NoSelector (Rec0 a)))) 
type (==) (Maybe k) a b = EqMaybe k a b 

data Either a b :: * -> * -> *

The Either type represents values with two possibilities: a value of type Either a b is either Left a or Right b.

The Either type is sometimes used to represent a value which is either correct or an error; by convention, the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value (mnemonic: "right" also means "correct").

Examples

The type Either String Int is the type of values which can be either a String or an Int. The Left constructor can be used only on Strings, and the Right constructor can be used only on Ints:

>>> let s = Left "foo" :: Either String Int
>>> s
Left "foo"
>>> let n = Right 3 :: Either String Int
>>> n
Right 3
>>> :type s
s :: Either String Int
>>> :type n
n :: Either String Int

The fmap from our Functor instance will ignore Left values, but will apply the supplied function to values contained in a Right:

>>> let s = Left "foo" :: Either String Int
>>> let n = Right 3 :: Either String Int
>>> fmap (*2) s
Left "foo"
>>> fmap (*2) n
Right 6

The Monad instance for Either allows us to chain together multiple actions which may fail, and fail overall if any of the individual steps failed. First we'll write a function that can either parse an Int from a Char, or fail.

>>> import Data.Char ( digitToInt, isDigit )
>>> :{
    let parseEither :: Char -> Either String Int
        parseEither c
          | isDigit c = Right (digitToInt c)
          | otherwise = Left "parse error"
>>> :}

The following should work, since both '1' and '2' can be parsed as Ints.

>>> :{
    let parseMultiple :: Either String Int
        parseMultiple = do
          x <- parseEither '1'
          y <- parseEither '2'
          return (x + y)
>>> :}
>>> parseMultiple
Right 3

But the following should fail overall, since the first operation where we attempt to parse 'm' as an Int will fail:

>>> :{
    let parseMultiple :: Either String Int
        parseMultiple = do
          x <- parseEither 'm'
          y <- parseEither '2'
          return (x + y)
>>> :}
>>> parseMultiple
Left "parse error"

Constructors

Left a 
Right b 

Instances

MonadError e (Either e) 
Monad (Either e) 
Functor (Either a) 
Applicative (Either e) 
Foldable (Either a) 
Traversable (Either a) 
Generic1 (Either a) 
Eq a => Eq1 (Either a) 
Ord a => Ord1 (Either a) 
Read a => Read1 (Either a) 
Show a => Show1 (Either a) 
(Eq a, Eq b) => Eq (Either a b) 
(Ord a, Ord b) => Ord (Either a b) 
(Read a, Read b) => Read (Either a b) 
(Show a, Show b) => Show (Either a b) 
Generic (Either a b) 
(Arbitrary a, Arbitrary b) => Arbitrary (Either a b) 
(CoArbitrary a, CoArbitrary b) => CoArbitrary (Either a b) 
(Outputable a, Outputable b) => Outputable (Either a b) 
(Lift a, Lift b) => Lift (Either a b) 
(PrettyVar a, PrettyVar b) => PrettyVar (Either a b) 
type Rep1 (Either a) = D1 D1Either ((:+:) (C1 C1_0Either (S1 NoSelector (Rec0 a))) (C1 C1_1Either (S1 NoSelector Par1))) 
type Rep (Either a b) = D1 D1Either ((:+:) (C1 C1_0Either (S1 NoSelector (Rec0 a))) (C1 C1_1Either (S1 NoSelector (Rec0 b)))) 
type (==) (Either k k1) a b = EqEither k k1 a b 

data Int :: *

A fixed-precision integer type with at least the range [-2^29 .. 2^29-1]. The exact range for a given implementation can be determined by using minBound and maxBound from the Bounded class.