বিমূর্ত উইকিপিডিয়া/আপডেট/2022-01-13
◀ | বিমূর্ত উইকিপিডিয়া আপডেট | ▶ |
শুভ নববর্ষ, ২০২২ সালের প্রথম নিউজ লেটারে স্বাগত!
When we started work on Wikifunctions, we divided the work into eleven functional phases, named after the first eleven letters of the Greek alphabet (a naming scheme that has received notoriety recently). We are currently working on Phase η (eta), with the goal of entirely re-doing the function model of Wikifunctions by allowing for generic types and functions.
Following discussions within the team, we are refining the completion criteria for the current phase, in order to make it more tangible. The original idea of how to show that we had completed the phase was that we would do a lot of very deep static validation, so that a function call such as:
- (১)
if(head([true]), false, true)
would validate, but
- (২)
if(head(["text"]), false, true)
would not. To explain: the if
function requires a Boolean
as the first argument, but head
is currently defined as head(List) → Object
. So in a static analysis, if
requires a Boolean
but gets an Object
. But if we would say that this is OK, the static analysis for both (1) and (2) would pass - and (2) shouldn’t pass.
On the other hand, as well as static analysis we have dynamic analysis, which happens when running the code. In that one, (1) should pass and return false
, whereas (2) should raise a type error during evaluation (something such as “if
expects a Boolean
on the first argument, but got a String
”).
We decided to de-scope the deep static analysis for now. This is something that we can add later, possibly after launching Wikifunctions.org. As you can see, users would get error messages one way or the other: it is just a question of when exactly the error is raised. Also, if you are interested in working on these or similar topics, please reach out. We are always happy to integrate the work of volunteers and other external partners.
Instead of this static analysis, we decided to focus on the following capabilities as examples of how the phase will have been completed:
- Being able to implement
curry
as a composition on the wiki, but without requiring strict static analysis - Making it possible to create the following three 'user-defined' types on the wiki:
positive integer
,sign
, andinteger
- Being able to make a generic wrapper type through composition on the wiki
- Providing a re-designed function editor (though this might be pushed into the next phase)
Let’s dive deeper into each of these capabilities.
Curry
For this to work, a user must be able to use a function as an argument, and use that function for a function call in the implementation of curry
. What is curry? Curry is a standard function in computer science that takes a function f and another object x and runs the function on the object. The standard form is that the function f has two arguments, the first one being of the type of x, and the 'output' is a call to the function f with the second argument preset to the value x. Example: given a function that appends a string to another string, I could create a new function “add s to end
” by calling curry(append, "s")
. We want to make it possible to define and call such a function.
User-defined types
Positive Integer
নিচের জিনিসগুলো বাস্তবায়ন করতে হবে:
- Create a new type,
Positive Integer
, with a single keyvalue
of typeString
- Create a function to validate
Positive Integer
- If
value
contains a character which is not a digit (0-9), the validator raises a user-created error with the non-digit character - If
value
contains leading zeros and is not just a single zero, the validator raises a user-created error - If
value
is an empty string, the validator raises a user-created error
- If
- Connect the validator to the
Positive Integer
type - Create the following eight functions:
Is zero: Positive Integer → Boolean
(returnsTrue
if the argument is zero andFalse
otherwise)Successor: Positive Integer → Positive Integer
(returns the argument increased by one)- Provide implementations in JavaScript (
BigInt
) and Python (bignum
)
- Provide implementations in JavaScript (
Predecessor: Positive Integer → Positive Integer
(returns the argument decreased by one, raises an error in case the argument is zero)- Provide implementations in JavaScript (
BigInt
) and Python (bignum
)
- Provide implementations in JavaScript (
Positive Integer: String → Positive Integer
(constructor)Positive Integer as String: Positive Integer → String
(deconstructor)Equal Positive Integer: Positive Integer, Positive Integer → Boolean
(whether the two numbers have the same value)Greater Than: Positive Integer, Positive Integer → Boolean
(whether the first number is bigger than the second)Lesser Than: Positive Integer, Positive Integer → Boolean
(whether the second number is bigger than the first)
Sign
The following things will be possible, related to the mathematics term "sign":
- Create a new type,
Sign
, with a single keyidentity
of typeSign
- Create the three possible values of type
Sign
, i.e.positive
,negative
, andneutral
- Create a function to validate
Sign
- If the value is not one of the expected three values, raise an error
- Connect the validator to the
Sign
type - Create the following function:
Equal sign: Sign, Sign → Boolean
(returns True if the two arguments have the same value)
Integer
নিম্নোক্ত জিনিসগুলো সম্ভব হবে:
- Create a new type,
Integer
, with two keys,absolute value
of typePositive Integer
andsign
of typeSign
- Create a function to validate
Integer
- Ensure that both keys are validated
- If
sign
isneutral
andabsolute value
is notzero
, or vice versa, raise an error
- Connect the validator with the
Integer
type - Create the following six functions:
Integer: Positive Integer, Sign → Integer
(constructor)Absolute value: Integer → Positive Integer
(deconstructor)Sign: Integer → Sign
(deconstructor)Equal Integer: Integer, Integer → Boolean
(whether the two numbers have the same value)Greater Than: Integer, Integer → Boolean
(whether the first number is bigger than the second)Lesser Than: Integer, Integer → Boolean
(whether the second number is bigger than the first)
Generic wrapper
A generic wrapper is a function that takes a type and returns a newly constructed type that has a single key with a value of that type. Wrappers may be useful for example to make sure that we don’t accidentally treat something as a number that looks a lot like a number. It is also useful as a test case because it is a rather simple generic type.
- Create a function that creates the generic type, i.e.
Wrap Type: Type → Type
- Create a generic constructor function, i.e.
Wrap: Type T → Function
which is a function that returns a function of signatureT → Wrap Type(T)
- Create a generic deconstructor function, i.e.
Unwrap: Type T → Function
which is a function that returns a function of signatureWrap Type(T) → T
- Store a literal of type
Wrap Type(Boolean)
as an object on the wiki - Write a generic function that creates a function that works with
Wrap Type(T)
, e.g.Wrapped Equality: Type T → λ: Wrap(T), Wrap(T) → Boolean
- Note that all these functions should be possible to be written entirely in user space
- Test by calling something like
Unwrap(Boolean)(Wrap(Boolean)(True))
and getTrue
back
পরবর্তীতে কী?
এই ধাপের আরও কিছু কাজ বাকি রয়েছে। তবে প্রায় সকল অংশই যথাযথভাবে সম্পূর্ণ হয়েছে। এই ধাপটি সম্পূর্ণ হলেই আমরা বেটা ক্লাস্টার প্রস্তুতের দিকে মন দেবো যেন আপনারা তা ব্যবহার করতে পারেন।
নতুন বছরের জন্য সবাইকে শুভ কামনা!