This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env nix-shell | |
#! nix-shell -i runghc -p "haskellPackages.ghcWithPackages (p: [p.aeson p.polysemy p.polysemy-plugin])" | |
{-# LANGUAGE BlockArguments #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE TypeApplications #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Adhoc where | |
data ClientIdentifier | |
= Admin | |
| User String | |
deriving (Eq, Show) | |
data Settings = Settings | |
{settingAllowList :: [ClientIdentifier]} | |
deriving (Show) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Adhoc where | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env nix-shell | |
#! nix-shell -i runghc -p "haskellPackages.ghcWithPackages (p: [p.effectful p.effectful-th])" | |
{-# LANGUAGE BlockArguments #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE GHC2021 #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE TemplateHaskell #-} | |
{-# LANGUAGE TypeFamilies #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
checkUserForPromotion :: User -> Either String User | |
checkUserForPromotion user = | |
case (user.age > 18, user.country, length user.purchases > 5) of | |
(True, France, True) -> Right (user { status = Vip }) | |
(False, _, _) -> Left "trop jeune" | |
(True, _, False) -> Left "pas assez d'achats" | |
(True, _, True) -> Left "pas français" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function creer_doublon($max) { | |
$start = 1; | |
$nombres = range(1, $max); | |
array_push($nombres, rand(1, $max)); | |
shuffle($nombres); | |
return $nombres; | |
} | |
print_r(creer_doublon(10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun read-only-chars (stream chars) | |
(with-output-to-string (result) | |
(loop while (find (peek-char nil stream) chars) | |
do (princ (read-char stream) result)))) | |
(set-dispatch-macro-character #\# #\! (lambda (stream subchar arg) | |
(parse-integer (remove #\_ (read-only-chars stream "01_")) :radix 2))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
(define digits12 "0123456789AB") | |
(define digits12-list (string->list digits12)) | |
(define (digit12->int digit) | |
(let loop ((digits digits12-list) | |
(result 0)) | |
(if (char=? digit (first digits)) | |
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ql:quickload "hunchentoot") | |
(use-package :hunchentoot) | |
(start (make-instance 'acceptor :port 8080)) | |
(define-easy-handler (greet :uri "/hello") (name) | |
(format nil "<html><body><h1>Hello ~a!</h1></body></html>" name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; the most straightforward imperative implementation of the while | |
; control structure | |
(defmacro while1 (cond &body body) | |
(with-gensyms (cond-var) | |
`(do ((,cond-var ,cond ,cond)) | |
((not ,cond-var)) | |
,@body))) | |
; a functional implementation relying on TCO | |
(defmacro while2 (cond &body body) |
NewerOlder