# Difference between revisions of "List of partial functions"

From HaskellWiki

(→Partial functions in Prelude: removed some functions that aren't in the Prelude) |
Josephcsible (talk | contribs) (add witnesses for all of them) |
||

(7 intermediate revisions by 4 users not shown) | |||

Line 1: | Line 1: | ||

==Partial functions in Prelude== |
==Partial functions in Prelude== |
||

+ | |||

+ | ===Functions that aren't even partial=== |
||

+ | |||

+ | {| class="wikitable" |
||

+ | ! Function |
||

+ | ! Witness |
||

+ | |- |
||

+ | | error |
||

+ | | error "x" |
||

+ | |- |
||

+ | | undefined |
||

+ | | undefined |
||

+ | |} |
||

===List functions=== |
===List functions=== |
||

− | * maximum |
||

+ | {| class="wikitable" |
||

− | * minimum |
||

+ | ! Function |
||

− | * head |
||

+ | ! Only partial for infinite lists |
||

− | * tail |
||

+ | ! Witness |
||

− | * init |
||

+ | |- |
||

− | * last |
||

+ | | maximum |
||

− | * foldl |
||

+ | | No |
||

− | * foldl' |
||

+ | | maximum [] |
||

− | * foldl1 |
||

+ | |- |
||

− | * foldl1' |
||

+ | | minimum |
||

− | * foldr1 |
||

+ | | No |
||

− | * scanl1 |
||

+ | | minimum [] |
||

− | * scanr1 |
||

+ | |- |
||

− | * cycle |
||

+ | | head |
||

− | * !! |
||

+ | | No |
||

− | * length |
||

+ | | head [] |
||

− | * sum |
||

+ | |- |
||

− | * product |
||

+ | | tail |
||

− | * reverse |
||

+ | | No |
||

− | * ... (todo) |
||

+ | | tail [] |
||

+ | |- |
||

+ | | init |
||

+ | | No |
||

+ | | init [] |
||

+ | |- |
||

+ | | last |
||

+ | | No |
||

+ | | last [] |
||

+ | |- |
||

+ | | foldl |
||

+ | | Yes |
||

+ | | foldl (const (const ())) () [0..] |
||

+ | |- |
||

+ | | foldl' |
||

+ | | Yes |
||

+ | | foldl' (const (const ())) () [0..] |
||

+ | |- |
||

+ | | foldl1 |
||

+ | | No |
||

+ | | foldl1 (const (const ())) [] |
||

+ | |- |
||

+ | | foldl1' |
||

+ | | No |
||

+ | | foldl1' (const (const ())) [] |
||

+ | |- |
||

+ | | foldr1 |
||

+ | | No |
||

+ | | foldr1 (const (const ())) [] |
||

+ | |- |
||

+ | | cycle |
||

+ | | No |
||

+ | | cycle [] |
||

+ | |- |
||

+ | | !! |
||

+ | | No |
||

+ | | [] !! 0 |
||

+ | |- |
||

+ | | filter |
||

+ | | Yes |
||

+ | | filter (const False) [0..] |
||

+ | |- |
||

+ | | dropWhile |
||

+ | | Yes |
||

+ | | dropWhile (const True) [0..] |
||

+ | |- |
||

+ | | length |
||

+ | | Yes |
||

+ | | length [0..] |
||

+ | |- |
||

+ | | sum |
||

+ | | Yes |
||

+ | | sum [0..] |
||

+ | |- |
||

+ | | product |
||

+ | | Yes |
||

+ | | product [0..] |
||

+ | |- |
||

+ | | reverse |
||

+ | | Yes |
||

+ | | reverse [0..] |
||

+ | |} |
||

===Other=== |
===Other=== |
||

− | * read |
||

+ | {| class="wikitable" |
||

− | * quot |
||

+ | ! Function |
||

− | * rem |
||

+ | ! Witness |
||

− | * quotRem |
||

+ | |- |
||

− | * div |
||

+ | | read |
||

− | * mod |
||

+ | | read "x" :: Int |
||

− | * divMod |
||

+ | |- |
||

− | * succ |
||

+ | | quot |
||

− | * pred |
||

+ | | 1 `quot` 0 |
||

− | * toEnum |
||

+ | |- |
||

− | * (^) |
||

+ | | rem |
||

− | * fail |
||

+ | | 1 `rem` 0 |
||

− | * ... (todo) |
||

+ | |- |
||

+ | | quotRem |
||

+ | | 1 `quotRem` 0 |
||

+ | |- |
||

+ | | div |
||

+ | | 1 `div` 0 |
||

+ | |- |
||

+ | | mod |
||

+ | | 1 `mod` 0 |
||

+ | |- |
||

+ | | divMod |
||

+ | | 1 `divMod` 0 |
||

+ | |- |
||

+ | | succ |
||

+ | | succ () |
||

+ | |- |
||

+ | | pred |
||

+ | | pred () |
||

+ | |- |
||

+ | | toEnum |
||

+ | | toEnum 1 :: () |
||

+ | |- |
||

+ | | (^) |
||

+ | | 1 ^ (-1) |
||

+ | |- |
||

+ | | fail |
||

+ | | fail "x" :: Either () () |
||

+ | |- |
||

+ | |colspan="2" | ... (todo) |
||

+ | |} |
||

==Partial functions in other base libraries== |
==Partial functions in other base libraries== |
||

Line 44: | Line 147: | ||

===Data.List=== |
===Data.List=== |
||

− | * genericIndex |
||

+ | {| class="wikitable" |
||

− | * genericLength |
||

+ | ! Function |
||

+ | ! Only partial for infinite lists |
||

+ | ! Witness |
||

+ | |- |
||

+ | | genericIndex |
||

+ | | No |
||

+ | | genericIndex [] 0 |
||

+ | |- |
||

+ | | genericLength |
||

+ | | Yes |
||

+ | | genericLength [0..] :: Integer |
||

+ | |} |
||

===Data.Map=== |
===Data.Map=== |
||

− | * (!) |
||

+ | {| class="wikitable" |
||

+ | ! Function |
||

+ | ! Witness |
||

+ | |- |
||

+ | | (!) |
||

+ | | Map.empty ! () |
||

+ | |} |
||

===Data.Maybe=== |
===Data.Maybe=== |
||

− | * fromJust |
||

+ | {| class="wikitable" |
||

+ | ! Function |
||

+ | ! Witness |
||

+ | |- |
||

+ | | fromJust |
||

+ | | fromJust Nothing |
||

+ | |} |
||

==Partial functions in other Haskell Platform packages== |
==Partial functions in other Haskell Platform packages== |
||

− | ... (todo) |
||

+ | {| class="wikitable" |
||

+ | ! Function |
||

+ | ! Witness |
||

+ | |- |
||

+ | |colspan="2" | ... (todo) |
||

+ | |} |

## Latest revision as of 22:14, 23 February 2019

## Contents

## Partial functions in Prelude

### Functions that aren't even partial

Function | Witness |
---|---|

error | error "x" |

undefined | undefined |

### List functions

Function | Only partial for infinite lists | Witness |
---|---|---|

maximum | No | maximum [] |

minimum | No | minimum [] |

head | No | head [] |

tail | No | tail [] |

init | No | init [] |

last | No | last [] |

foldl | Yes | foldl (const (const ())) () [0..] |

foldl' | Yes | foldl' (const (const ())) () [0..] |

foldl1 | No | foldl1 (const (const ())) [] |

foldl1' | No | foldl1' (const (const ())) [] |

foldr1 | No | foldr1 (const (const ())) [] |

cycle | No | cycle [] |

!! | No | [] !! 0 |

filter | Yes | filter (const False) [0..] |

dropWhile | Yes | dropWhile (const True) [0..] |

length | Yes | length [0..] |

sum | Yes | sum [0..] |

product | Yes | product [0..] |

reverse | Yes | reverse [0..] |

### Other

Function | Witness |
---|---|

read | read "x" :: Int |

quot | 1 `quot` 0 |

rem | 1 `rem` 0 |

quotRem | 1 `quotRem` 0 |

div | 1 `div` 0 |

mod | 1 `mod` 0 |

divMod | 1 `divMod` 0 |

succ | succ () |

pred | pred () |

toEnum | toEnum 1 :: () |

(^) | 1 ^ (-1) |

fail | fail "x" :: Either () () |

... (todo) |

## Partial functions in other base libraries

### Data.List

Function | Only partial for infinite lists | Witness |
---|---|---|

genericIndex | No | genericIndex [] 0 |

genericLength | Yes | genericLength [0..] :: Integer |

### Data.Map

Function | Witness |
---|---|

(!) | Map.empty ! () |

### Data.Maybe

Function | Witness |
---|---|

fromJust | fromJust Nothing |

## Partial functions in other Haskell Platform packages

Function | Witness |
---|---|

... (todo) |