Quick Setup

Posted on September 2, 2022
Tags: codeetc

1 Haskell

Creates a new folder helloworld at current directory

stack new helloworld new-template

1.1 running

stack run ./app/Main.hs
1.1.0.0.1 running interactive

runs an interactive env

stack ghci ./app/Main.hs
1.1.0.0.2 build+execute
stack build
stack exec hello-world

1.1.1 Go

package main

import (
	"fmt"
)

func main() {
	var a string = "hello"
	var bb []byte = []byte(a[0:3])
	var c string = a[1:3]

	fmt.Printf("%s\n", a)
	fmt.Printf("%s\n", string(bb))
	fmt.Printf("%s\n", c)
}
go run hello.go

1.1.2 Go Modules

  1. project folder
mkdir goworld
cd goworld
  1. Create greetings modules
mkdir greetings
cd greetings
go mod init example.com/greetings
#this creates go.mod

create a file called greetings.go

package greetings

import "fmt"

// Hello returns a greeting for the named person.
func Hello(name string) string {
    // Return a greeting that embeds the name in a message.
    message := fmt.Sprintf("Hi, %v. Welcome!", name)
    return message
}
  1. executable folder
cd ..
mkdir hello
cd hello
go mod init example.com/hello
package main

import (
    "fmt"

    "example.com/greetings"
)

func main() {
    // Get a greeting message and print it.
    message := greetings.Hello("Gladys")
    fmt.Println(message)
}
  1. setup local
    typically our modules will be held on our webserver at (in this case) “example.com/greetings”
    To run locally

in your hello dir

go mod edit -replace example.com/greetings=../greetings
go mod tidy
  1. running

inside hello dir

go run .

1.1.3 C

running

gcc -o bleh main.c
./bleh