What is pattern matching in the sphere theory, is it an intermediary shot, or is it a program-specific idea?

Asked 2 years ago, Updated 2 years ago, 54 views

DataHow do I access the first element of the type?As I asked you in , Haskell may only have a pattern match method to retrieve data.

Example (from above link answer):

dataShape=Rect Double Double
getX(Rect xy) = x
getX(Rect 1.0 2.0)

Now, Hakell seems to have created a language based on sphere theory, but where is this pattern matching in sphere theory?

Background of the question
I've been studying Haskell for a long time, but I don't really understand it anymore, and I understood this pattern matching easily because I experienced unwrap on Swift's Optional.

Swift Optional Unwrap Description

As a result, this data extraction method (unwrap) has become common in Haskell as well as Swift, and I think it has become a major programming technique.This technique (unwrap) is also available in Kotlin as well as in Swfit.

(I think the pattern matching method is similar to this unwrap, but Swift is probably not influenced by the sphere theory, so maybe it's completely different. Or optional and pattern matching have nothing to do with Swift's How to retrieve data from the attached enum switch may look more like a pattern match)

Search for Spheric programming language CPL-Ryusei's Notes (a.k.a.M59 blog)

So what does the intermediary fire deal with?Haskell's Either type defines the function either::(a->c)->(b->c)->Either ab->c, which is equivalent to the case of CPL's coprod.f:A->C, g:B->C, case(f,g):coprod(A,B)->C.

So, I've just tried CPL, so I don't know what to do, but I was wondering if this intermediation is the way to retrieve data by pattern matching.

You may need to learn about spheres from the basics, but if this pattern matching data extraction has nothing to do with spheres in the first place, it has nothing to do with what you want to know now, so I want to know if it has anything to do with it.

Now that there are two techniques, unwrap and pattern matching, I'm not sure which one to focus on (in Haskell's example, I have to use pattern matching to extract data (unwrap), so I think it's better.

haskell

2022-09-30 19:55

1 Answers

You may have already solved it yourself, but just for your information.

I think that the cosmological interpretation of pattern matching may be aggressive, but it is certainly possible, so it is not irrelevant at all it has nothing to do with it.
As long as you have at least spheresically meaningful operations, you can essentially extract elements of the more primitive type used to construct the type from the values of the type defined as algebraic data types by their combinations.
(If you ask me if there is a more general and uniform interpretation, I don't know because I'm not that specialized.)

First, under ideal circumstances that ignore the presence of undefined and unsafe functions, the Haskell type and the entire function between them form a single sphere of Hask.
Here, when a, b are any object in the sphere, there are always objects in the sphere that have a special meaning, called the surplus object (coproduct object) or the product object (product object).(It might be more correct to say that the language is designed to do so.The remainder is also called sum (sum).

The specific definitions and meanings of these concepts are left to nLab and spheresy textbooks, but in conclusion,

  • Hask surplus

    • Expand a+b
      Either ab
    • Incident i1:a→a+b
      Left::a->Either ab
    • Incident i2:b→a+b
      Right::b->Either ab
    • Intermediary shooting for surplus [h,k]:a+b→c
      either hk
  • Products in Hask

    • Product target a×b
      (a,b)
    • Projection p1:a×b→a
      fst::(a,b)->a
    • Projection p2:a×b→b
      snd::(a,b)->b
    • Product targetIntermediated <h,k>:c→a×b
      ((<*>).fmap(,))::(c->a)->(c->b)->(c->(a,b)))hk

Additional product in Hask

  • Expand a+b
    Either ab
  • Incident i1:a→a+b
    Left::a->Either ab
  • Incident i2:b→a+b
    Right::b->Either ab
  • Intermediary shooting for surplus [h,k]:a+b→c
    either hk

Product in Hask

  • Product target a×b
    (a,b)
  • Projection p1:a×b→a
    fst::(a,b)->a
  • Projection p2:a×b→b
    snd::(a,b)->b
  • Product targetIntermediated <h,k>:c→a×b
    ((<*>).fmap(,))::(c->a)->(c->b)->(c->(a,b)))hk

and so on.

Now, what I'm going to show you is whether extracting internal data from an algebraic data type can be accomplished only by purely spheroidal operations (i.e., deductions using only spheroidal properties such as "all finite products and finite products" and "Calcsian closed" without reference to the target internal representation.

Shape=Rect Double Double | Tri Double Double Double

The algebraic data type is, in terms of spheres, Double×Double+(Double×Double) between Double×Double. Rect and Tri respectively correspond to incident i1:(Double×Double)→(Double×Double)+(Double×Double), i2:(Double×Double)→(Double×Double)+(Double×Double×Double).At this point, the element of interest

x:1→(Double×Double)+(Double×Double))

If you think about , first of all, since the incident on the element is fortunately the product of the same object (Double×Double) in this example is the product of the same object (folding) [id, id]:(Double×Double)+(Double×Double)→(Double×Double×Double) (Haskell function) multiplied by

(x [[id,id]): 1 → (Double x Double)

You can remove the incident from the pair of values of the elements to be stacked.
Also, if you take a projection on this product (Double×Double) element,

(x [[id,id]⨟p1):1→Double
(x [[id,id] ]p2):1→Double

Without mentioning the internal configuration of the target, you can get the two numeric data you want only through a spheresic operation.

If the residual object consists of two different objects a, b, such as a+b, it is not possible in principle to remove the incident as it is, but by preparing a function f:b→a that processes the value of one type,

id,f —a+b→a

You can replace it with a function that removes the incident that hangs on the value of type a and converts the value of type b into the value of type a with a separately prepared f.

Incidentally, if you think of a function ((Double×Double)+(Double×Double))→Double, you don't have to take out internal data and define a function while referring to them.→Double×Double→Double (Double×Double) のDouble (Double×Double) 射Double (Double) is the target product of If you rephrase it using Haskell's function, this shot is

either(uncurry(*))(/2).uncurry(*))

However, if you actually do the following, it will work as you can see.

either(uncurry(*))(/2).uncurry(*))$Left(3,4)--12.0
ether(uncurry(*))(/2).uncurry(*))$Right(3,4)--6.0

As described in Wiki, algebraic data types are essentially a combination of surplus and product, so internal data can be handled spheresically in the same way as in this example.For example, if 1 is the terminating object, or the type () in the Hask,

dataBool=True|False--1+1
data Maybe a=Nothing | Just a --1+a
data Foo=Blah1 | Blah2 Double | Blah3 --(1+Double)+1

All of these algebraic data types can be interpreted as spheresically constructed objects.

Back to the main topic, for pattern matching in this question, the Shape type is

dataShape=Rect Double Double

Although defined as , this can be understood as Double×Double in terms of spheres, and the linked "left object intermediation = pattern match branching" to the product object is not very relevant in this scene, and the two projections accompanying the product fst:::(Double, Double, Double, Double, Double;Double;Double;Double;Double;Double;Double;I think it's a view that it's being reduced to

Add

While I misunderstood that the meaning of intermediate shooting was caused by any two shots with a common co-domain within the range that satisfies the universality of the remainder, I made some corrections because intermediate shooting had a more general meaning.

"I have read the link carefully again, but it seems that the definition of ""universal shooting from a target in zone D to a target in zone F:C→D"" or ""universal shooting from a target in zone D"" is generally called ""intermediary shooting."""
Specifically, "any pair of shootings h:a→c,k:b→c with two common co-domains <h,k>:<a,b>→ )(c)" from "Hask×Hask target <a,b>角:Hask→Hask×Hask universal shootings <i1,i2>>>+(a)→

  • Unique shot from any object a to the ending object 1!:a→1
    (const() in Haskell's function)

  • Shooting from two shots h:c→a,k:c→b with any common domain to the production target a×b<h,k>:c→a×b

  • Shooting from c caused by any shot f:c×a→b to an exponential object b^a ff:c→(b^a)
    (curryf in Haskell's function)

  • Injection rec(x,f):N→a
    from the natural number object N to a caused by the self-quasi-isomorphism f:a→a of elements x and a of any object a (N and Int are different, so they are strictly different, but pseudo-Haskell functions represent (curry.flip$iterate))xf)

Unique shot connecting any object a to the ending object 1!:a→1
(const() in Haskell's function)

Two shots h:c→a,k:b with any common domain to the production object a×b caused by k:c→a,c→b<h,k>:c aa×b

An injection ff:c→(b^a)
from c caused by any injection f:c×a→b to an exponential object b^a. (curryf in Haskell's function)

Rec(x,f):N→a
from the natural number object N to a caused by the self-quasi-isomorphism f:a→a of elements x and a of any object a (N and Int are different, so they are strictly different, but pseudo-Haskell functions represent (curry.flip$iterate))xf)

and so on are all called intermediary shots.

I'm sorry.


2022-09-30 19:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.