Lilac [she/her]

  • 1 Post
  • 13 Comments
Joined 3 years ago
cake
Cake day: March 23rd, 2022

help-circle
  • Lilac [she/her]toScience Memes@mander.xyzpick your side
    link
    fedilink
    English
    arrow-up
    2
    ·
    edit-2
    7 months ago

    Your link directly contradicts what you said?

    If colours were simply a naming scheme for wavelengths then pink is not one

    However, colours are not simply names for wavelengths – colours merely label our perception of light, once it has passed through our eyes.





  • Lilac [she/her]toMemes@lemmy.ml6÷2(1+2)
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    Kinda. You can’t define a name, but you can get the compiler to interpret literals as a function. If you have a Num instance for (Integer -> Integer) where,

    fromInteger i = \x -> x * i

    the compiler can interpret integer literals as functions like so

    x = 2(5) :: Integer





  • Typed functional languages usually do, as mentioned by others. This is form of Algebraic Data Type called a Sum Type (as oppose to a Product type, which is basically a normal struct).

    Here’s some examples of creating a binary tree in different languages (also Lemmy’s code formatter is terrible)

    Examples

    Haskell

    data Tree a = Empty | Leaf a | Node (Tree a) (Tree a)

    F#

    type Tree<'a> = Empty | Leaf of 'a | Node of (Tree<'a> * Tree<'a>)

    Scala

    sealed trait Tree[+A]

    case class Empty[A]() extends Tree[A]

    case class Leaf[A](a: A) extends Tree[A]

    case class Node[A](left: Tree[A], right: Tree[A]) extends Tree[A]

    Rust

    enum Tree<T> {

    Empty,

    Leaf(T),

    Node(Box<Tree<T>>, Box<Tree<T>>),

    }