Results for “shape”

30 results, best first

  1. definitionReference › Glossary shape A list of functions a type must have. Any type with those functions fits the shape, with nothing to declare on the type. Shapes are how you write a function that works for many types. shape Area { fn…
  2. The language › Structs, enums and shapes Shapes: structural generics A shape names a set of functions. Any type that has those functions fits the shape; there is nothing to declare on the type. shape Area { fn area(self): float } struct Circle { r: float } struct…
  3. The language › Structs, enums and shapes The built-in shapes shape needs gives you Show fn show(self): str print, str(x), "{x}" Eq fn eq(self, o: Self): bool ==, !=, contains, unique, map keys Ord fn cmp(self, o: Self): int (negative, zero or positive) < >…
  4. error codeError codes E0105: shape used where a type is expected, or a type where a shape is expected A shape (like Show or Ord) is a type only in a function signature, where it means "some type that fits". Elsewhere a value of any fitting type is written any Show. Conversely, a bound or any needs a…
  5. error codeError codes E0113: malformed shape A shape lists methods that a type must have to fit it. Each method must take self first, and a shape itself can't have type parameters (inside a shape, Self names the fitting type).
  6. error codeError codes E0350: type doesn't fit a shape A shape (like Show, Ord or your own) asks for certain functions. This type lacks one, so it can't be used where the shape is needed. The note names the missing function.
  7. error codeError codes E0415: conversion to any Shape exceeds the shape method's effects A value converted to any Shape is called through the shape's methods, which declare what effects they may use. Here the type's method uses more than the shape declares, so calling it through the…
  8. Reference › Cheat sheet Structs, enums, shapes …3.0, ..p } // ..p comes last let r = Point { x, y } enum Shape { Circle(r: float), Rect(w: float, h: float) } let s = Circle(2.0) shape Area { fn area(self): float } // structural: any type with…
  9. The language › Structs, enums and shapes Enums …between variants, and each variant may carry fields: enum Shape { Circle(r: float), Rect(w: float, h: float), Empty, } fn area(s: Shape): float = match s { Circle(r) => 3.14159 * r * r Rect(w, h) =>…
  10. definitionReference › Glossary enum A type that is one of several named choices, each of which can carry its own data. enum Shape { Circle(r: float), Rect(w: float, h: float) } More: Structs, enums and shapes.
  11. definitionReference › Glossary struct A type that groups named fields. struct Point { x: float, y: float } More: Structs, enums and shapes.
  12. Start here › Getting started A program with something to check enum Shape { Circle(r: float), Rect(w: float, h: float) } fn area(Circle(r)): float = 3.14159 * r * r fn area(Rect(w, h)): float = w * h fn parse_side(s: str): float! { let x = float.parse(s) else…
  13. The language › Functions, clauses and patterns Clauses …int = 1 fn fib(n: int): int = fib(n - 1) + fib(n - 2) enum Shape { Circle(r: float), Rect(w: float, h: float) } fn area(Circle(r)): float = 3.14159 * r * r fn area(Rect(w, h)): float = w * h fn…
  14. The language › Functions, clauses and patterns Patterns …separated by newlines or commas and may have guards: enum Shape { Circle(r: float), Rect(w: float, h: float) } fn describe(s: Shape): str = match s { Circle(r) => "circle of radius {r}" Rect(w, h)…
  15. Start here › A tour of Auk 2. Choices, and functions by cases …More: Functions, clauses and patterns, Structs, enums and shapes.
  16. The language › Effects The rule …pass it down. Guards (when) and contracts must be pure. A shape's method declares the effects it may use: shape Log { fn log(self, s: str) uses fs }. A type whose method does more than the shape…
  17. The language › Modules and packages A file is a module …of an application src/pricing.auk module `pricing` src/geo/shapes.auk module `geo.shapes` .raft/ installed dependencies (generated; don't commit) raft new shop creates this layout (raft new shop…
  18. The language › Modules and packages No imports …no import lines to write or to keep in order: // src/geo/shapes.auk pub struct Rect { w: float, h: float } pub fn area(r: Rect): float = r.w * r.h fn helper(): int = 1 // private: no `pub` //…
  19. The language › Modules and packages Visibility …its module unless marked pub: functions, structs, enums, shapes and top-level lets. Using a private item from elsewhere is E0120, and the message tells you what to mark. A pub struct's fields are…
  20. error codeError codes › E0105: shape used where a type is expected, or a type where a shape is expected Common causes Using a shape as a variable or field type: write any Show. A struct type used as a generic bound: fn f<T: Point>(...).
  21. error codeError codes › E0113: malformed shape Wrong shape Area { fn area(): float }
  22. error codeError codes › E0113: malformed shape Fixed shape Area { fn area(self): float }
  23. error codeError codes › E0415: conversion to any Shape exceeds the shape method's effects Wrong shape Log { fn log(self, s: str) } struct F { p: str } fn log(f: F, s: str) uses fs { fs.write(f.p, s) else () } fn report(l: any Log) { l.log("hi") } fn main() { report(F { p: "a" }) }
  24. error codeError codes › E0415: conversion to any Shape exceeds the shape method's effects Fixed shape Log { fn log(self, s: str) uses fs } struct F { p: str } fn log(f: F, s: str) uses fs { fs.write(f.p, s) else () } fn report(l: any Log) uses fs { l.log("hi") } fn main() uses fs { report(F {…
  25. Working on Auk › Compiler architecture Pipeline …(build) names patterns, RC/control C-like IR effects, flow shapes Written in Auk. The compiler is the Auk project compiler/ (compiler/src/main.auk), built by ./build.sh from a seed auk (the previous…
  26. Working on Auk › Compiler architecture Source layout …the full AST: items (fn clause, struct, enum, shape, test, top-level let/imprint), patterns, expressions, types; every node has a Span compiler/src/parser.auk recursive descent; precedence climbing…
  27. Working on Auk › raft design notes Project layout …for apps src/lib.auk root module for libraries src/geo/shapes.auk module `geo.shapes` .raft/ installed packages (generated; don't commit) A package's root module is src/lib.auk; its items are reached…
  28. Reference › Cheat sheet Functions …fs { ... } // can fail, returns nothing pub fn area(s: Shape): float { ... } // pub = visible to other modules The last expression is returned. return, break, continue and fail(e) are expressions…
  29. Tools › raft, the package manager Writing a package …reached as geo.<item>; other files are submodules (src/shapes.auk is geo.shapes). Declare the smallest effects list you can. A package with none can be added to any project. If only one function…
  30. error codeError codes › E0105: shape used where a type is expected, or a type where a shape is expected Wrong fn main() { let v: Show = 1 print(v.show()) }