1 kyu
Scott Encoding
534 of 609xenoexplorator
Description:
Can you make algebraic data types even more functional? Of course!
Scott encoding represents data as funtion that apply their argument (also a function) to their value. This approach is similar to using pattern matching on regular ADTs to extract and use their content.
You are given types representing the Scott encoding of four common Haskell types: Maybe, lists, Either and pairs (2-tuples).
Your task is to implement conversion functions between these regular types and their Scott encoding.
In addition, you will have to implement the following common operations using the provided Scott-encoded data types:
fst
andsnd
, functions to extract the content of a pairswap
, a function that exchanges the content of a paircurry
, a function to turn functions of pairs into functions of two argumentsuncurry
, a function to turn functions of two arguments into functions of pairs
isJust
andisNothing
, predicates testing wether a Maybe contains data
isLeft
andisRight
, predicates testing which side is contained in an Eithercons
, a function to prepend an element to a listconcat
, a function to contanetate two lists
catMaybes
, a function to flatten a list of Maybes by removing Nothings
null
, a predicate testing wether a list is empty
length
, a function returning the number of elements in a listmap
, a function to transform the contents of a list according to a given functionzip
, a funtion to merge two lists into a list of pairspartition
, a function that splits a list of Eithers in a pair of Lefts and Rights
foldl
andfoldr
, functions to reduce a list to a single value by successive application of a given function
take
, a function to limit a list to a number of initial elements
Functional Programming
Fundamentals
Similar Kata:
Stats:
Created | Sep 19, 2017 |
Published | Sep 19, 2017 |
Warriors Trained | 1585 |
Total Skips | 92 |
Total Code Submissions | 7593 |
Total Times Completed | 609 |
Haskell Completions | 534 |
Scala Completions | 82 |
Total Stars | 102 |
% of votes with a positive feedback rating | 94% of 168 |
Total "Very Satisfied" Votes | 151 |
Total "Somewhat Satisfied" Votes | 14 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 7 |
Average Assessed Rank | 1 kyu |
Highest Assessed Rank | 1 kyu |
Lowest Assessed Rank | 2 kyu |