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
libraryDependencies += "com.chuusai" % "shapeless_2.11" % "2.3.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
val list1 : List[Int] = List(1,2,3) // list of integers | |
val list2 : List[String] = List("a","b", "c") // list of strings | |
val list3 : List[Any] = List(1,2,"a","b") // list of any. Here Any is the least upper bound of sting & int |
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
import shapeless._ | |
val hlist1a = HList(1,2,3) | |
val hlist2a = HList(1,"a",3.14) | |
// The above code with type ascription | |
val hlist1b: ::[Int, ::[Int, ::[Int, HNil]]] = HList(1,2,3) | |
val hlist2b: ::[Int, ::[String, ::[Double, HNil]]] = HList(1,"a",3.15) |
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
val l = 1 :: "hello" :: true :: HNil | |
// l: shapeless.::[Int,shapeless.::[String,shapeless.::[Boolean,shapeless.HNil]]] = 1 :: hello :: true :: HNil | |
l.head | |
// res7: Int = 1 | |
l.tail | |
// res8: shapeless.::[String,shapeless.::[Boolean,shapeless.HNil]] = hello :: true :: HNil | |
l(1) |
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 IParsec | |
interface Source a where | |
feed : Nat -> a -> (List Char, a) | |
next : a -> (List Char, a) | |
next = feed 1 | |
Source String where | |
feed x string = let (first, second) = splitAt x $ unpack string in | |
(first, pack second) |
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
import Text.ParserCombinators.Parsec | |
import Data.List | |
type Args = [String] | |
type Body = [String] | |
type Label = String | |
data JSONProp = JSONProp Label JSON deriving Show | |
data JSON = JSONObject [JSONProp] | |
| JSONNumber Double |
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
{- | |
Zachary Weaver <[email protected]> | |
JSONParser.hs | |
Version 0.1.1 | |
A simple example of parsing JSON with Parsec in haskell. Note that | |
since the primary point of this excersize is demonstration, | |
Text.Parsec.Token was avoided to expose more of the grammar. Also, | |
complicated optimizations and shorcuts were avoided (mostly). |
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
use std::fmt::*; | |
/// A struct that represents a single node in a list | |
/// | |
/// # State | |
/// * `element` - The element of type T that is stored in the node | |
/// * `next` - An optional value that points to the next element in the list | |
#[derive(PartialEq, Debug)] | |
pub struct Node<T: Debug> { | |
pub element: T, |
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
• Couldn't match type ‘Circle’ with ‘Line’ | |
Expected type: Tree Line | |
Actual type: Tree Circle | |
• In the expression: Node (Circle (20, 30) 50) [] | |
In the second argument of ‘Node’, namely | |
‘[Node (Circle (20, 30) 50) []]’ | |
In the expression: | |
Node (Line (100, 100) (30, 60)) [Node (Circle (20, 30) 50) []] | |
| | |
11 | sampleTree = Node (Line (100,100) (30,60)) [Node (Circle (20,30) 50) []] |
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
{-# LANGUAGE ExistentialQuantification, GADTs #-} | |
module Main where | |
class SvgNode a where | |
toSVG :: a -> String | |
data SvgNodeObject where | |
Pack :: SvgNode a => a -> SvgNodeObject | |
OlderNewer