This repository has been archived by the owner on Oct 7, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.stack-work/ | ||
*~ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
This is a starting point for Haskell solutions to the | ||
["Build Your Own Redis" Challenge](https://codecrafters.io/challenges/redis). | ||
|
||
In this challenge, you'll build a toy Redis clone that's capable of handling | ||
basic commands like `PING`, `SET` and `GET`. Along the way we'll learn about | ||
event loops, the Redis protocol and more. | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to signup for early access. | ||
|
||
# Usage | ||
|
||
1. Ensure you have `stack` installed locally | ||
1. Run `./spawn_redis_server.sh` to run your Redis server, which is implemented | ||
in `Main.hs`. | ||
1. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. | ||
|
||
# Passing the first stage | ||
|
||
CodeCrafters runs tests when you do a `git push`. Make an empty commit and push | ||
your solution to see the first stage fail. | ||
|
||
```sh | ||
git commit --allow-empty -m "Running tests" | ||
git push origin master | ||
``` | ||
|
||
You should see a failure message that says it wasn't able to connect to port | ||
`6379`. | ||
|
||
Go to `Main.hs` and uncomment the server implementation. Commit and push your | ||
changes, and you'll now see the first stage pass. | ||
|
||
Time to move on to the next stage! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
module Main where | ||
|
||
|
||
import Network.Socket | ||
( SocketType(..) | ||
, Family(..) | ||
, SocketOption(..) | ||
, SockAddr(..) | ||
, socket | ||
, listen | ||
, bind | ||
, accept | ||
, setSocketOption | ||
, defaultProtocol | ||
) | ||
|
||
|
||
|
||
main :: IO () | ||
main = do | ||
putStrLn "Your code goes here" | ||
|
||
-- Uncomment this to pass stage 1 | ||
-- sock <- socket AF_INET Stream defaultProtocol | ||
-- setSocketOption sock ReuseAddr 1 | ||
-- bind sock (SockAddrInet 6379 0) | ||
-- listen sock 5 | ||
-- _ <- accept sock | ||
-- return () |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the Haskell version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: haskell-8.8 | ||
language_pack: haskell-8.8 |
26 changes: 26 additions & 0 deletions
26
compiled_starters/redis-starter-haskell/hs-redis-clone.cabal
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
cabal-version: 1.12 | ||
|
||
-- This file has been generated from package.yaml by hpack version 0.33.1. | ||
-- | ||
-- see: https://github.com/sol/hpack | ||
-- | ||
-- hash: 0177d91e1489b3789c8fb1e24a39a79433a73c6996dd37db0e17c800a32f4daa | ||
|
||
name: hs-redis-clone | ||
version: 0.1.0.0 | ||
license: BSD3 | ||
build-type: Simple | ||
|
||
executable hs-redis-clone-exe | ||
main-is: Main.hs | ||
other-modules: | ||
Paths_hs_redis_clone | ||
hs-source-dirs: | ||
app | ||
ghc-options: -threaded -rtsopts -with-rtsopts=-N | ||
build-depends: | ||
attoparsec | ||
, base >=4.7 && <5 | ||
, bytestring | ||
, network | ||
default-language: Haskell2010 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: hs-redis-clone | ||
version: 0.1.0.0 | ||
license: BSD3 | ||
|
||
# Metadata used when publishing your package | ||
# synopsis: Short description of your package | ||
# category: Web | ||
|
||
dependencies: | ||
- base >= 4.7 && < 5 | ||
- network | ||
- bytestring | ||
# We recommend using attoparsec for your parsing needs while implementing the RESP | ||
# parser, but the final call is upto you! | ||
- attoparsec | ||
|
||
executables: | ||
hs-redis-clone-exe: | ||
main: Main.hs | ||
source-dirs: app | ||
ghc-options: | ||
- -threaded | ||
- -rtsopts | ||
- -with-rtsopts=-N |
2 changes: 2 additions & 0 deletions
2
compiled_starters/redis-starter-haskell/spawn_redis_server.sh
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
stack run --silent |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# This file was automatically generated by 'stack init' | ||
# | ||
# Some commonly used options have been documented as comments in this file. | ||
# For advanced use and comprehensive documentation of the format, please see: | ||
# https://docs.haskellstack.org/en/stable/yaml_configuration/ | ||
|
||
# Resolver to choose a 'specific' stackage snapshot or a compiler version. | ||
# A snapshot resolver dictates the compiler version and the set of packages | ||
# to be used for project dependencies. For example: | ||
# | ||
# resolver: lts-3.5 | ||
# resolver: nightly-2015-09-21 | ||
# resolver: ghc-7.10.2 | ||
# | ||
# The location of a snapshot can be provided as a file or url. Stack assumes | ||
# a snapshot provided as a file might change, whereas a url resource does not. | ||
# | ||
# resolver: ./custom-snapshot.yaml | ||
# resolver: https://example.com/snapshots/2018-01-01.yaml | ||
resolver: lts-16.0 | ||
|
||
# User packages to be built. | ||
# Various formats can be used as shown in the example below. | ||
# | ||
# packages: | ||
# - some-directory | ||
# - https://example.com/foo/bar/baz-0.0.2.tar.gz | ||
# subdirs: | ||
# - auto-update | ||
# - wai | ||
packages: | ||
- . | ||
# Dependency packages to be pulled from upstream that are not in the resolver. | ||
# These entries can reference officially published versions as well as | ||
# forks / in-progress versions pinned to a git hash. For example: | ||
# | ||
# extra-deps: | ||
# - acme-missiles-0.3 | ||
# - git: https://github.com/commercialhaskell/stack.git | ||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a | ||
# | ||
# extra-deps: [] | ||
|
||
# Override default flag values for local packages and extra-deps | ||
# flags: {} | ||
|
||
# Extra package databases containing global packages | ||
# extra-package-dbs: [] | ||
|
||
# Control whether we use the GHC we find on the path | ||
# system-ghc: true | ||
# | ||
# Require a specific version of stack, using version ranges | ||
# require-stack-version: -any # Default | ||
# require-stack-version: ">=2.3" | ||
# | ||
# Override the architecture used by stack, especially useful on Windows | ||
# arch: i386 | ||
# arch: x86_64 | ||
# | ||
# Extra directories used by stack for building | ||
# extra-include-dirs: [/path/to/dir] | ||
# extra-lib-dirs: [/path/to/dir] | ||
# | ||
# Allow a newer minor version of GHC than the snapshot specifies | ||
# compiler-check: newer-minor |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This file was autogenerated by Stack. | ||
# You should not edit this file by hand. | ||
# For more information, please see the documentation at: | ||
# https://docs.haskellstack.org/en/stable/lock_files | ||
|
||
packages: [] | ||
snapshots: | ||
- completed: | ||
size: 531237 | ||
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/0.yaml | ||
sha256: 210e15b7043e2783115afe16b0d54914b1611cdaa73f3ca3ca7f8e0847ff54e5 | ||
original: lts-16.0 |