StaDyn (programming language)

StaDyn
ParadigmObject oriented
Designed byFrancisco Ortin[1]
DeveloperComputational Reflection research group[2] of the University of Oviedo
First appeared2007; 17 years ago (2007)
Stable release
2.2.1 / 11 May 2022; 2 years ago (2022-05-11)
Typing disciplineHybrid static and dynamic typing, gradual typing, strong, inferred
Implementation languageC#
PlatformCommon Language Infrastructure (.NET Framework)
LicenseMIT License[3]
Websitereflection.uniovi.es/stadyn
Major implementations
C#
Influenced by
C#, OCaml, StrongTalk, Boo

StaDyn is an object-oriented general-purpose programming language for the .NET platform that supports both static and dynamic typing in the same programming language.

The StaDyn compiler gathers type information for the dynamically typed code. That type information is used to detect type errors at compilation time and to perform significant optimizations. For that purpose, it provides type reconstruction (inference), flow-sensitive types, union and intersection types, constraint-based typing, alias analysis and method specialization. Its first prototype appeared in 2007, as a modification of C# 3.0. Type inference was supported by including var as a new type, unlike C#, which only offers var to define initialized local variables. Flow-sensitive types of var references are inferred by the compiler, providing type-safe duck typing.[4] When a more lenient approach is required by the programmer, the dynamictype could be used instead of var. Although type inference is still performed, dynamic references behave closer to those in dynamic languages.

StaDyn is designed by Francisco Ortin[1] from the University of Oviedo. The language has been implemented by different members of the Computational Reflection research group,[2] including Miguel Garcia, Jose Baltasar García Perez-Schofield and Jose Quiroga, besides Francisco Ortin.

The name StaDyn is a portmanteau of static and dynamic, denoting its aim to provide the benefits of both static and dynamic typing.

Code samples

Variables with different types

Just like dynamic languages, variables may hold different types in the same scope:

using System;
class Program {
    public static void Main() {
        Console.Write("Number: ");
        var age = Console.In.ReadLine();
        Console.WriteLine("Digits: " + age.Length);

        age = Convert.ToInt32(age);
        age++;

        Console.WriteLine("Happy birthday, you are " + age +
                          " years old now.");
        int length = age.Length; // * Compiler error
    }
}

The age variable is first inferred as string, so it is safe to get its Length property. Then, it holds an integer, so age++ is a valid expression. The compiler detects an error in the last line, since Length is no longer provided by age.

The generated code does not use a single Object variable to represent age, but two different variables whose types are string and int. This is achieved with a modification of the algorithm to compute the SSA form.[5] This makes the generated code to be more efficient, since runtime type conversions are not required.

Flow-sensitive types

var and dynamic variables can hold flow-sensitive types:

using System;
class Program {
    public static void Main(String[] args) {
        var exception;
        if (args.Length > 0)
            exception = new ApplicationException("An application exception.");
        else
            exception = new SystemException("A system exception.");
        Console.WriteLine(exception.Message);
    }
}

It is safe to get the Message property from exception because both ApplicationException and SystemException provide that property. Otherwise, a compiler error is shown. In this way, StaDyn provides a type-safe static duck-typing system.

In the following program:

using System;
class Program {
    public static void Main(String[] args) {
        var exception;
        switch (args.Length) {
        case 0: 
            exception = new ApplicationException("An application exception.");
            break;
        case 1:
            exception = new SystemException("A system exception.");
            break;
        default:
            exception = "This is not an exception.";
            break;
        }
        Console.WriteLine(exception.Message); // * Compiler error with var, but not with dynamic
        Console.WriteLine(exception.Unknown); // * Compiler error
    }
}

The Message property is not provided by String, so a compiler error is shown for exception.Message. However, if we declare exception as dynamic, the previous program is accepted by the compiler. dynamic is more lenient than var, following the flavor of dynamic languages. However, static type checking is still performed. This is shown in the last line of code, where the compiler shows an error for exception.Unknown even if exception is declared as dynamic. This is because neither of the three possible types (ApplicationException, SystemException and String) supports the Unknown message.[6]

Although dynamic and var types can be used explicitly to obtain safer or more lenient type checking, the dynamism of single var references can also be modified with command-line options, XML configuration files and a plugin for Visual Studio.[7]

Type inference of fields

var and dynamic types can be used as object fields:

class Wrapper {
    private var attribute;

    public Wrapper(var attribute) {
        this.attribute = attribute;
    }

    public var get() {
        return attribute;
    }

    public void set(var attribute) {
        this.attribute = attribute;
    }
}

class Test {
    public static void Main() {
        string aString;
        int aInt;
        Wrapper wrapper = new Wrapper("Hello");
        aString = wrapper.get();
        aInt = wrapper.get(); // * Compiler error

        wrapper.set(3);
        aString = wrapper.get(); // * Compiler error
        aInt = wrapper.get();
    }
}

The Wrapper class can wrap any type. Each time we call the set method, the type of attribute is inferred as the type of the argument. Each object has a potentially different type of attribute, so its type is stored for every single instance rather than for the whole class. In this way, the two lines indicated in the code above report compilation errors. A type-based alias analysis algorithm is implemented to support this behavior.[8]

Constraint-based types

Let's analyze the following method:

public static var upper(var parameter) {
    return parameter.ToUpper();
}

The type of parameter and the function return value are inferred by the compiler. To that aim, a constraint is added to the type of the upper method: the argument must provide a ToUpper method with no parameters. At each invocation, the constraint will be checked. Additionally, the return type of upper will be inferred as the return type of the corresponding ToUpper method implemented by the argument.[9]

The programmer may use either var or dynamic to declare parameter, changing the way type checking is performed upon method invocation. Let's assume that the argument passed to upper holds a flow-sensitive type (e.g., the ApplicationException, SystemException or String exception variable in the code above). With var, all the possible types of the argument must provide ToUpper; with dynamic, at least one type must provide ToUpper.

Runtime performance

The type information gathered by StaDyn is used to perform significant optimizations in the generated code: [10] the number of type inspections and type casts are reduced, reflection is avoided, frequent types are cached, and methods with constraints are specialized. The point of all the optimizations is to reduce the number of type-checking operations performed at runtime, which is the main performance penalty of most dynamic languages. Many of those type checks are undertaken earlier by the StaDyn compiler. A detailed evaluation of the runtime performance of StaDyn is detailed in.[4]

See also

References

  1. ^ a b "Francisco Ortin". uniovi.es. Retrieved May 17, 2022.
  2. ^ a b "Computational Reflection Research Group". uniovi.es. Retrieved May 17, 2022.
  3. ^ "StaDyn Download". uniovi.es. Retrieved May 17, 2022.
  4. ^ a b Francisco Ortin; Miguel Garcia; Sean McSweeney (2019). "Rule-based program specialization to optimize gradually typed code". Knowledge-Based Systems. 179: 145–173. doi:10.1016/j.knosys.2019.05.013. hdl:10651/53505. S2CID 182002303.
  5. ^ Jose Quiroga; Francisco Ortin (2017). "SSA Transformations to Facilitate Type Inference in Dynamically Typed Code". The Computer Journal. doi:10.1093/comjnl/bxw108.
  6. ^ Francisco Ortin; Miguel Garcia (2011). "Union and intersection types to support both dynamic and static typing". Information Processing Letters. 111 (6): 278–286. doi:10.1016/j.ipl.2010.12.006. hdl:10651/8732.
  7. ^ Francisco Ortin; Francisco Morero; Anton Morant (2014). "Static type information to improve the IDE features of hybrid dynamically and statically typed languages". Journal of Visual Languages & Computing. 25 (4): 346–362. doi:10.1016/j.jvlc.2014.04.002.
  8. ^ Francisco Ortin; Daniel Zapico; J.B.G. Perez-Schofield; Miguel Garcia (2010). "Including both static and dynamic typing in the same programming language". IET Software. 4 (4): 268. doi:10.1049/iet-sen.2009.0070. hdl:10651/9769.
  9. ^ Francisco Ortin (2011). "Type Inference to Optimize a Hybrid Statically and Dynamically Typed Language". The Computer Journal. 54 (11): 1901–1924. doi:10.1093/comjnl/bxr067. hdl:10651/11411.
  10. ^ Miguel Garcia; Francisco Ortin; Jose Quiroga (2016). "Design and implementation of an efficient hybrid dynamic and static typing language". Software: Practice and Experience. 46 (2): 199–226. doi:10.1002/spe.2291. S2CID 2065468.

Read other articles:

Assorted GemsGenreRomansa, Keluarga, DramaDitulis olehIm Sung-hanSutradaraBaek Ho-minPemeranGo Na-eun Lee Tae-gon So Yi-hyun Lee Hyun-jin Lee Il-minNegara asalKorea SelatanBahasa asliKoreaJmlh. episode50ProduksiProduserKim Jeong-hoLokasi produksiKorea SelatanDurasi60 menit Sabtu dan Minggu pukul 21:45 (WSK)Rilis asliJaringanMunhwa Broadcasting CorporationFormat audioStereoRilis5 September 2009 (2009-09-05) –21 Februari 2010 (2010-2-21) Assorted Gems (Hangul: 보석�...

 

هذه المقالة تحتاج للمزيد من الوصلات للمقالات الأخرى للمساعدة في ترابط مقالات الموسوعة. فضلًا ساعد في تحسين هذه المقالة بإضافة وصلات إلى المقالات المتعلقة بها الموجودة في النص الحالي. (أغسطس 2023) دوري المؤسسات (كركوك)الموسم1948–49البطلالذهب الأسود(اللقب الأول)هابطونشانت الأر...

 

Artikel ini bukan mengenai Naser al-Din Shah Qajar. Naseeruddin ShahNaseeruddin Shah pada 2011LahirNaseeruddin Shah20 Juli 1950 (umur 73)[a]Barabanki, Uttar Pradesh, IndiaKebangsaanIndiaPekerjaanPemeran, Pemerhati lingkungan hidupTahun aktif1972–sekarangKarya terkenalKarma,Mirza Ghalib (1989) The Perfect Murder, A Wednesday, Sarfarosh, Khuda Ke Liye, Monsoon Wedding, Masoom,Zinda Bhaag, The Extraordinary Gentlemen, IqbalSuami/istriParveen Murad, juga dikenal sebagai Manara...

This article may contain an excessive amount of intricate detail that may interest only a particular audience. Please help by spinning off or relocating any relevant information, and removing excessive detail that may be against Wikipedia's inclusion policy. (January 2013) (Learn how and when to remove this template message) Major League Roller HockeySportInline hockeyFounded1998, Alexandria, Virginia, United StatesFirst season1998CEODoug JonesPresidentBill RaueCountryUnited StatesHeadquarter...

 

Village in Devon, England This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.Find sources: Milton Combe – news · newspapers · books · scholar · JSTOR (February 2024) (Learn how and when to remove this template message) 50°28′19″N 4°07′59″W / 50.472°N 4.133°W / 50.472; -4.133 Milton Combe C...

 

William SmithSir William Smith pada 1893Lahir(1813-05-20)20 Mei 1813Municipal Borough of EnfieldMeninggal7 Oktober 1893(1893-10-07) (umur 80)MakamHighgate CemeteryAlmamater University College London University College School PekerjaanLeksikografer and editorKarya A Dictionary of Greek and Roman Antiquities Dictionary of Greek and Roman Biography and Mythology Dictionary of Greek and Roman Geography William Smith (leksikografer). William Smith Kt. (1813–1893) adalah seorang leksikograf...

This is the chronological list of horror films produced in Malayalam cinema. Bhargavi Nilayam, released in December 1964, is considered as the first true horror film in the language. The film was scripted by writer Vaikom Muhammed Basheer based on his own short story Neelavelicham. It was produced by T. K. Pareekutty under the banner Chandrathara Films. The film, which is now considered as a classic in Malayalam cinema, celebrated its Golden Jubilee in 2014.[1] Films Year Title Direc...

 

American screenwriter (born 1970) For the mobster, see Nicholas Santora. This article includes a list of general references, but it lacks sufficient corresponding inline citations. Please help to improve this article by introducing more precise citations. (March 2013) (Learn how and when to remove this template message) Nick SantoraSantora at the 2014 Comic-Con InternationalOccupation(s)Writer, producer Nick Santora (born 1970) is a writer and producer born in Queens, New York. He won the Bes...

 

This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these template messages) The topic of this article may not meet Wikipedia's notability guidelines for companies and organizations. Please help to demonstrate the notability of the topic by citing reliable secondary sources that are independent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the articl...

Gomme-laque Copeaux de laque. Identification No CAS 9000-59-3 No CE 232-549-9 PubChem 6850749 No E E904 Propriétés physiques T° fusion 75 °C[1] Masse volumique 1,1 g·cm-3 [1] Précautions NFPA 704[1] 120  Directive 67/548/EEC[1] Phrases S : S36 : Porter un vêtement de protection approprié.S24/25 : Éviter le contact avec la peau et les yeux.Phrases S : 24/25, 36, Unités du SI et CNTP, sauf indication contraire. modifier  La gomme-laque, ou...

 

此條目可参照英語維基百科相應條目来扩充。 (2021年10月13日)若您熟悉来源语言和主题,请协助参考外语维基百科扩充条目。请勿直接提交机械翻译,也不要翻译不可靠、低品质内容。依版权协议,译文需在编辑摘要注明来源,或于讨论页顶部标记{{Translated page}}标签。 国际调查记者同盟International Consortium of Investigative Journalists成立時間1997年總部华盛顿哥伦比亚特区 地址�...

 

1998 single by Mike OldfieldMan in the RainSingle by Mike Oldfieldfrom the album Tubular Bells III Released5 October 1998 (1998-10-05)GenrePop rockLength4:01LabelWarnerSongwriter(s)Mike OldfieldProducer(s)Mike OldfieldMike Oldfield singles chronology Tubular X (1998) Man in the Rain (1998) Far Above the Clouds (1999) Man in the Rain is a pop rock song written and performed by English multi-instrumentalist Mike Oldfield. It was included on the album Tubular Bells III and release...

هذه المقالة تحتاج للمزيد من الوصلات للمقالات الأخرى للمساعدة في ترابط مقالات الموسوعة. فضلًا ساعد في تحسين هذه المقالة بإضافة وصلات إلى المقالات المتعلقة بها الموجودة في النص الحالي. (مايو 2016) اضغط هنا للاطلاع على كيفية قراءة التصنيف بوتيا مودستا حالة الحفظ أنواع غير مهدد�...

 

County in Tennessee, United States Not to be confused with Dyer, Tennessee. County in TennesseeDyer CountyCountyDyer County Courthouse in Dyersburg in 2022Location within the U.S. state of TennesseeTennessee's location within the U.S.Coordinates: 36°04′N 89°25′W / 36.06°N 89.41°W / 36.06; -89.41Country United StatesState TennesseeFounded1823Named forRobert Henry Dyer, state legislator[1]SeatDyersburgLargest cityDyersburgArea • Tota...

 

State in northern India State in North India, IndiaUttar PradeshStateTaj MahalSarnathIIT VaranasiDudhwa National ParkKashi Vishwanath TempleAgra Fort Emblem of Uttar PradeshEtymology: Northern ProvinceMotto: Satyameva Jayate (Truth alone triumphs)Location of Uttar Pradesh in IndiaCoordinates: 26°51′N 80°55′E / 26.85°N 80.91°E / 26.85; 80.91Country IndiaRegionNorth IndiaBefore wasUnited Provinces (1937–1950)Formation24 January 1950[1] Capital...

Elezioni presidenziali in Mongolia del 2021Stato Mongolia Data9 giugno Candidati Ukhnaagiin Khürelsükh Dangaasürengiin Enkhbat Sodnomzunduin Erdene Partiti MAN Zöv Khün AN Voti 823.32672,02% 246.96821,60% 72.8326,37% Distribuzione del voto per provincia Presidente uscenteKhaltmaagiin Battulga (AN) 2017 2025 Le elezioni presidenziali in Mongolia del 2021 si sono tenute il 9 giugno. Risultati Candidati Partiti Voti % Ukhnaagiin Khürelsükh Partito del Popolo Mongolo 823 326 72,...

 

35th Infantry DivisionActiveOctober 1936 – May 1945Country Nazi GermanyBranchArmyTypeInfantrySizeDivisionMilitary unit The 35th Infantry Division (German: 35. Infanteriedivision) was a German Army infantry division in World War II. History The 35th Infantry Division was raised in October 1936 in Germany's re-militarisation. It was mostly used on the eastern front. In May 1940, the division was part of the German forces sent to invade France and Belgium, remaining as an occupational for...

 

「日本橋三井タワー」とは異なります。 この項目には、一部のコンピュータや閲覧ソフトで表示できない文字(Microsoftコードページ932(はしご高))が含まれています(詳細)。 東京日本橋タワー 中央通りを挟んだ南東側より。手前のクレーンは本ビルとは別の、南隣の再開発事業によるもの。 施設情報所在地 東京都中央区日本橋二丁目7番1号座標 北緯35度40分55秒 �...

レイ・チャップマンRay Chapman 1917年基本情報国籍 アメリカ合衆国出身地 ケンタッキー州ビーバーダム(英語版)生年月日 1891年1月15日没年月日 (1920-08-17) 1920年8月17日(29歳没)身長体重 5' 10 =約177.8 cm170 lb =約77.1 kg選手情報投球・打席 右投右打ポジション 遊撃手プロ入り 1910年初出場 1912年8月30日最終出場 1920年8月16日経歴(括弧内はプロチーム在籍年度) クリーブラ�...

 

President of Germany from 1919 to 1925 For Friedrich Ebert's son, a leading politician in East Germany, see Friedrich Ebert Jr. For the German bibliographer and librarian, see Friedrich Adolf Ebert. Friedrich EbertEbert in 1925President of GermanyIn office11 February 1919 – 28 February 1925Minister President(1919)Philipp ScheidemannGustav BauerChancellor(1919–1925)Gustav BauerHermann MüllerConstantin FehrenbachJoseph WirthWilhelm CunoGustav StresemannWilhelm MarxHans Luther...